From: Jérôme Benoit Date: Sat, 8 Jul 2023 22:34:53 +0000 (+0200) Subject: test: fix wrong async/await usage in describe() X-Git-Tag: v2.6.11~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=079de9913bd2a225fe8f08c51be74b1f4d4a78d4;p=poolifier.git test: fix wrong async/await usage in describe() Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 687ae25f..19272508 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -158,18 +158,20 @@ export abstract class AbstractPool< } protected checkDynamicPoolSize (min: number, max: number): void { - if (this.type === PoolTypes.dynamic && min > max) { - throw new RangeError( - 'Cannot instantiate a dynamic pool with a maximum pool size inferior to the minimum pool size' - ) - } else if (this.type === PoolTypes.dynamic && min === 0 && max === 0) { - throw new RangeError( - 'Cannot instantiate a dynamic pool with a minimum pool size and a maximum pool size equal to zero' - ) - } else if (this.type === PoolTypes.dynamic && min === max) { - throw new RangeError( - 'Cannot instantiate a dynamic pool with a minimum pool size equal to the maximum pool size. Use a fixed pool instead' - ) + if (this.type === PoolTypes.dynamic) { + if (min > max) { + throw new RangeError( + 'Cannot instantiate a dynamic pool with a maximum pool size inferior to the minimum pool size' + ) + } else if (min === 0 && max === 0) { + throw new RangeError( + 'Cannot instantiate a dynamic pool with a minimum pool size and a maximum pool size equal to zero' + ) + } else if (min === max) { + throw new RangeError( + 'Cannot instantiate a dynamic pool with a minimum pool size equal to the maximum pool size. Use a fixed pool instead' + ) + } } } diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 6daec140..c638663f 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -3,7 +3,7 @@ const { FixedClusterPool, PoolEvents } = require('../../../lib') const { WorkerFunctions } = require('../../test-types') const { waitPoolEvents, waitWorkerEvents } = require('../../test-utils') -describe('Fixed cluster pool test suite', async () => { +describe('Fixed cluster pool test suite', () => { const numberOfWorkers = 6 const pool = new FixedClusterPool( numberOfWorkers, @@ -12,9 +12,6 @@ describe('Fixed cluster pool test suite', async () => { errorHandler: e => console.error(e) } ) - let poolReady = 0 - pool.emitter.on(PoolEvents.ready, () => ++poolReady) - await waitPoolEvents(pool, PoolEvents.ready, 1) const queuePool = new FixedClusterPool( numberOfWorkers, './tests/worker-files/cluster/testWorker.js', @@ -81,6 +78,16 @@ describe('Fixed cluster pool test suite', async () => { }) it("Verify that 'ready' event is emitted", async () => { + const pool1 = new FixedClusterPool( + numberOfWorkers, + './tests/worker-files/cluster/testWorker.js', + { + errorHandler: e => console.error(e) + } + ) + let poolReady = 0 + pool1.emitter.on(PoolEvents.ready, () => ++poolReady) + await waitPoolEvents(pool1, PoolEvents.ready, 1) expect(poolReady).toBe(1) }) diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index 8b2fe420..b2842f6e 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -3,7 +3,7 @@ const { FixedThreadPool, PoolEvents } = require('../../../lib') const { WorkerFunctions } = require('../../test-types') const { waitPoolEvents, waitWorkerEvents } = require('../../test-utils') -describe('Fixed thread pool test suite', async () => { +describe('Fixed thread pool test suite', () => { const numberOfThreads = 6 const pool = new FixedThreadPool( numberOfThreads, @@ -12,9 +12,6 @@ describe('Fixed thread pool test suite', async () => { errorHandler: e => console.error(e) } ) - let poolReady = 0 - pool.emitter.on(PoolEvents.ready, () => ++poolReady) - await waitPoolEvents(pool, PoolEvents.ready, 1) const queuePool = new FixedThreadPool( numberOfThreads, './tests/worker-files/thread/testWorker.js', @@ -81,6 +78,16 @@ describe('Fixed thread pool test suite', async () => { }) it("Verify that 'ready' event is emitted", async () => { + const pool1 = new FixedThreadPool( + numberOfThreads, + './tests/worker-files/thread/testWorker.js', + { + errorHandler: e => console.error(e) + } + ) + let poolReady = 0 + pool1.emitter.on(PoolEvents.ready, () => ++poolReady) + await waitPoolEvents(pool1, PoolEvents.ready, 1) expect(poolReady).toBe(1) })