fix: properly handle dynamic pool with zero minimum size
[poolifier.git] / tests / pools / thread / dynamic.test.mjs
index 06cf64c64081353b9b5db74aed8b2dc39088ffa7..9d35ce8aa8088b58809b4c54d67ec2712e06d974 100644 (file)
@@ -152,4 +152,23 @@ describe('Dynamic thread pool test suite', () => {
     // We need to clean up the resources after our test
     await pool.destroy()
   })
+
+  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)
+    expect(pool.workerNodes.length).toBe(pool.info.minSize)
+    const maxMultiplier = 10000
+    const promises = new Set()
+    for (let i = 0; i < max * maxMultiplier; i++) {
+      promises.add(pool.execute())
+    }
+    await Promise.all(promises)
+    expect(pool.workerNodes.length).toBe(max)
+    // We need to clean up the resources after our test
+    await pool.destroy()
+  })
 })