test: fix dynamic cluster pool with zero worker test
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 5 Jan 2024 23:07:05 +0000 (00:07 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 5 Jan 2024 23:07:05 +0000 (00:07 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
CHANGELOG.md
tests/pools/cluster/dynamic.test.mjs
tests/pools/thread/dynamic.test.mjs

index bd54238fd0bafb1d81da6a9ed41006bf0c74e6cb..38099740aa369ef53693cea7a0775d4c7cf9a0e6 100644 (file)
@@ -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
index d2a250c15b6b1032a6687634caa6cc905e115e00..540223bf2840ab384e11d4b077a5f84cd27a8144 100644 (file)
@@ -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()
   })
 })
index 2b5dd6112fac7c9664ec6a0ad7a0ce027aa4f371..77c5aaeb5afd3893c8c7eb265a7d65ed4d3cdda6 100644 (file)
@@ -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()
   })
 })