X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fcluster%2Ffixed.test.js;h=a5790db075f400b3ff4ff93dd6c0a01a3beb62fd;hb=a25c335d7e5573a171fc96c445cb6092852b2c4a;hp=30dbc3631b92de7c71b52e386b8a6115e75d83c8;hpb=8ebe6c308dc1fc3202980126da043b2855d24780;p=poolifier.git diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 30dbc363..a5790db0 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -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) @@ -220,9 +224,12 @@ describe('Fixed cluster pool test suite', () => { it('Shutdown test', async () => { const exitPromise = waitWorkerEvents(pool, 'exit', numberOfWorkers) + let poolDestroy = 0 + pool.emitter.on(PoolEvents.destroy, () => ++poolDestroy) await pool.destroy() const numberOfExitEvents = await exitPromise expect(numberOfExitEvents).toBe(numberOfWorkers) + expect(poolDestroy).toBe(1) }) it('Verify that cluster pool options are checked', async () => {