Merge pull request #886 from poolifier/dependabot/npm_and_yarn/examples/typescript...
[poolifier.git] / tests / pools / cluster / fixed.test.js
index 749cacaa4d4ade34727242e21caa1071be504b4c..a5790db075f400b3ff4ff93dd6c0a01a3beb62fd 100644 (file)
@@ -92,12 +92,14 @@ describe('Fixed cluster pool test suite', () => {
     expect(poolReady).toBe(1)
   })
 
-  it("Verify that 'busy' event is emitted", () => {
+  it("Verify that 'busy' event is emitted", async () => {
+    const promises = new Set()
     let poolBusy = 0
     pool.emitter.on(PoolEvents.busy, () => ++poolBusy)
     for (let i = 0; i < numberOfWorkers * 2; i++) {
-      pool.execute()
+      promises.add(pool.execute())
     }
+    await Promise.all(promises)
     // The `busy` event is triggered when the number of submitted tasks at once reach the number of fixed pool workers.
     // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the fixed pool.
     expect(poolBusy).toBe(numberOfWorkers + 1)
@@ -111,6 +113,7 @@ describe('Fixed cluster pool test suite', () => {
     }
     expect(promises.size).toBe(numberOfWorkers * maxMultiplier)
     for (const workerNode of queuePool.workerNodes) {
+      expect(workerNode.usage.tasks.executing).toBeGreaterThanOrEqual(0)
       expect(workerNode.usage.tasks.executing).toBeLessThanOrEqual(
         queuePool.opts.tasksQueueOptions.concurrency
       )
@@ -133,6 +136,7 @@ describe('Fixed cluster pool test suite', () => {
       numberOfWorkers *
         (maxMultiplier - queuePool.opts.tasksQueueOptions.concurrency)
     )
+    expect(queuePool.info.backPressure).toBe(false)
     await Promise.all(promises)
     for (const workerNode of queuePool.workerNodes) {
       expect(workerNode.usage.tasks.executing).toBe(0)