test: test for wait node readiness in dynamic pool
[poolifier.git] / tests / pools / selection-strategies / selection-strategies.test.mjs
index b7597b4c0c71d0f326fb866dbebb1d277474667f..127377a26118c5d5be57cf98661eb9139fe5d81f 100644 (file)
@@ -7,6 +7,7 @@ import {
   WorkerChoiceStrategies
 } from '../../../lib/index.js'
 import { CircularArray } from '../../../lib/circular-array.js'
+import { sleep } from '../../test-utils.js'
 
 describe('Selection strategies test suite', () => {
   const min = 0
@@ -174,6 +175,26 @@ describe('Selection strategies test suite', () => {
     await pool.destroy()
   })
 
+  it('Verify strategies wait for worker node readiness in dynamic pool', async () => {
+    const pool = new DynamicThreadPool(
+      min,
+      max,
+      './tests/worker-files/thread/testWorker.mjs'
+    )
+    await sleep(600)
+    expect(pool.starting).toBe(false)
+    expect(pool.workerNodes.length).toBe(min)
+    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()
+  })
+
   it('Verify ROUND_ROBIN strategy default policy', async () => {
     const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
     let pool = new FixedThreadPool(