From: Jérôme Benoit Date: Wed, 31 May 2023 12:46:03 +0000 (+0200) Subject: test: use Set for promises X-Git-Tag: v2.5.0~5 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=09c2d0d3bf72a566a9460155ef62b052e53411aa;p=poolifier.git test: use Set for promises Signed-off-by: Jérôme Benoit --- diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 108fb32a..1c014625 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -327,10 +327,10 @@ describe('Abstract pool test suite', () => { numberOfWorkers, './tests/worker-files/cluster/testWorker.js' ) - const promises = [] + const promises = new Set() const maxMultiplier = 2 for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) { - promises.push(pool.execute()) + promises.add(pool.execute()) } for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ @@ -372,10 +372,10 @@ describe('Abstract pool test suite', () => { numberOfWorkers, './tests/worker-files/thread/testWorker.js' ) - const promises = [] + const promises = new Set() const maxMultiplier = 2 for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) { - promises.push(pool.execute()) + promises.add(pool.execute()) } await Promise.all(promises) for (const workerNode of pool.workerNodes) { @@ -422,7 +422,7 @@ describe('Abstract pool test suite', () => { numberOfWorkers, './tests/worker-files/thread/testWorker.js' ) - const promises = [] + const promises = new Set() let poolFull = 0 pool.emitter.on(PoolEvents.full, () => ++poolFull) for (let i = 0; i < numberOfWorkers * 2; i++) { @@ -440,7 +440,7 @@ describe('Abstract pool test suite', () => { numberOfWorkers, './tests/worker-files/thread/testWorker.js' ) - const promises = [] + const promises = new Set() let poolBusy = 0 pool.emitter.on(PoolEvents.busy, () => ++poolBusy) for (let i = 0; i < numberOfWorkers * 2; i++) { diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index dfd76557..ac5d1fda 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -113,7 +113,6 @@ describe('Fixed cluster pool test suite', () => { expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(maxMultiplier) expect(workerNode.tasksQueue.size).toBe(0) } - promises.clear() }) it('Verify that is possible to have a worker that return undefined', async () => { diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index 0c3ba276..ef368968 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -113,7 +113,6 @@ describe('Fixed thread pool test suite', () => { expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(maxMultiplier) expect(workerNode.tasksQueue.size).toBe(0) } - promises.clear() }) it('Verify that is possible to have a worker that return undefined', async () => {