From 079de9913bd2a225fe8f08c51be74b1f4d4a78d4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 9 Jul 2023 00:34:53 +0200 Subject: [PATCH] test: fix wrong async/await usage in describe() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 26 ++++++++++++++------------ tests/pools/cluster/fixed.test.js | 15 +++++++++++---- tests/pools/thread/fixed.test.js | 15 +++++++++++---- 3 files changed, 36 insertions(+), 20 deletions(-) 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) }) -- 2.34.1