From 6d7beb8c8cf0bdb1f5ef19f57fcfb0aa0e53f074 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 6 Jan 2024 00:07:05 +0100 Subject: [PATCH] test: fix dynamic cluster pool with zero worker test MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 4 ++++ tests/pools/cluster/dynamic.test.mjs | 22 ++++++++++++---------- tests/pools/thread/dynamic.test.mjs | 20 +++++++++++--------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd54238f..38099740 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix dynamic pool with minimum number of workers set to zero: [#1748](https://github.com/poolifier/poolifier/issues/1748). + ## [3.1.17] - 2024-01-05 ### Changed diff --git a/tests/pools/cluster/dynamic.test.mjs b/tests/pools/cluster/dynamic.test.mjs index d2a250c1..540223bf 100644 --- a/tests/pools/cluster/dynamic.test.mjs +++ b/tests/pools/cluster/dynamic.test.mjs @@ -157,15 +157,17 @@ describe('Dynamic cluster pool test suite', () => { await pool.destroy() }) - it.skip('Verify that a pool with zero worker works', async () => { - const pool = new DynamicClusterPool( - 0, - max, - './tests/worker-files/thread/testWorker.mjs' - ) - expect(pool.starting).toBe(false) + it('Verify that a pool with zero worker works', async () => { for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) { - pool.setWorkerChoiceStrategy(workerChoiceStrategy) + const pool = new DynamicClusterPool( + 0, + max, + './tests/worker-files/cluster/testWorker.cjs', + { + workerChoiceStrategy + } + ) + expect(pool.starting).toBe(false) expect(pool.readyEventEmitted).toBe(false) for (let run = 0; run < 2; run++) { run % 2 !== 0 && pool.enableTasksQueue(true) @@ -183,8 +185,8 @@ describe('Dynamic cluster pool test suite', () => { expect(pool.readyEventEmitted).toBe(false) expect(pool.workerNodes.length).toBe(pool.info.minSize) } + // We need to clean up the resources after our test + await pool.destroy() } - // We need to clean up the resources after our test - await pool.destroy() }) }) diff --git a/tests/pools/thread/dynamic.test.mjs b/tests/pools/thread/dynamic.test.mjs index 2b5dd611..77c5aaeb 100644 --- a/tests/pools/thread/dynamic.test.mjs +++ b/tests/pools/thread/dynamic.test.mjs @@ -158,14 +158,16 @@ describe('Dynamic thread pool test suite', () => { }) it('Verify that a pool with zero worker works', async () => { - const pool = new DynamicThreadPool( - 0, - max, - './tests/worker-files/thread/testWorker.mjs' - ) - expect(pool.starting).toBe(false) for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) { - pool.setWorkerChoiceStrategy(workerChoiceStrategy) + const pool = new DynamicThreadPool( + 0, + max, + './tests/worker-files/thread/testWorker.mjs', + { + workerChoiceStrategy + } + ) + expect(pool.starting).toBe(false) expect(pool.readyEventEmitted).toBe(false) for (let run = 0; run < 2; run++) { run % 2 !== 0 && pool.enableTasksQueue(true) @@ -183,8 +185,8 @@ describe('Dynamic thread pool test suite', () => { expect(pool.readyEventEmitted).toBe(false) expect(pool.workerNodes.length).toBe(pool.info.minSize) } + // We need to clean up the resources after our test + await pool.destroy() } - // We need to clean up the resources after our test - await pool.destroy() }) }) -- 2.34.1