]> Piment Noir Git Repositories - poolifier.git/commitdiff
test: relax destroy timeout assertion (#3253)
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 4 Jul 2026 16:43:56 +0000 (18:43 +0200)
committerGitHub <noreply@github.com>
Sat, 4 Jul 2026 16:43:56 +0000 (18:43 +0200)
tests/pools/abstract-pool.test.mjs

index 9748f9e602666fbf236543e2c426064f2845e2e4..8056b143f5d375d75b906bd059cdf8e80337d9f1 100644 (file)
@@ -1565,36 +1565,45 @@ describe('Abstract pool test suite', () => {
     )
   })
 
-  it('Verify that destroy() waits until the tasks finished timeout is reached', async () => {
-    const tasksFinishedTimeout = 1000
-    const pool = new FixedThreadPool(
-      numberOfWorkers,
-      './tests/worker-files/thread/asyncWorker.mjs',
-      {
+  for (const { PoolClass, workerFilePath, workerType } of [
+    {
+      PoolClass: FixedClusterPool,
+      workerFilePath: './tests/worker-files/cluster/asyncWorker.cjs',
+      workerType: WorkerTypes.cluster,
+    },
+    {
+      PoolClass: FixedThreadPool,
+      workerFilePath: './tests/worker-files/thread/asyncWorker.mjs',
+      workerType: WorkerTypes.thread,
+    },
+  ]) {
+    it(`Verify that destroy() waits until the tasks finished timeout is reached in a ${workerType} pool`, async () => {
+      const tasksFinishedTimeout = 1000
+      const pool = new PoolClass(numberOfWorkers, workerFilePath, {
         enableTasksQueue: true,
         tasksQueueOptions: { tasksFinishedTimeout },
-      }
-    )
-    const maxMultiplier = 4
-    let tasksFinished = 0
-    for (const workerNode of pool.workerNodes) {
-      workerNode.on('taskFinished', () => {
-        ++tasksFinished
       })
-    }
-    for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) {
-      pool.execute()
-    }
-    expect(pool.info.queuedTasks).toBeGreaterThan(0)
-    const startTime = performance.now()
-    await pool.destroy()
-    const elapsedTime = performance.now() - startTime
-    expect(tasksFinished).toBe(0)
-    // Worker kill message response timeout is 1000ms
-    expect(elapsedTime).toBeLessThanOrEqual(
-      tasksFinishedTimeout + 1000 * tasksFinished + 1000
-    )
-  })
+      const maxMultiplier = 4
+      let tasksFinished = 0
+      for (const workerNode of pool.workerNodes) {
+        workerNode.on('taskFinished', () => {
+          ++tasksFinished
+        })
+      }
+      for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) {
+        pool.execute()
+      }
+      expect(pool.info.queuedTasks).toBeGreaterThan(0)
+      const startTime = performance.now()
+      await pool.destroy()
+      const elapsedTime = performance.now() - startTime
+      expect(tasksFinished).toBe(0)
+      // Allow task timeout, 1000ms per kill response, and 100ms scheduling slack.
+      expect(elapsedTime).toBeLessThanOrEqual(
+        tasksFinishedTimeout + 1000 * tasksFinished + 1100
+      )
+    })
+  }
 
   it('Verify that pool asynchronous resource track tasks execution', async () => {
     let taskAsyncId