From 3a256294ba1afa98b889454343542e6793cf9513 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 4 Jul 2026 18:43:56 +0200 Subject: [PATCH] test: relax destroy timeout assertion (#3253) --- tests/pools/abstract-pool.test.mjs | 63 +++++++++++++++++------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/tests/pools/abstract-pool.test.mjs b/tests/pools/abstract-pool.test.mjs index 9748f9e60..8056b143f 100644 --- a/tests/pools/abstract-pool.test.mjs +++ b/tests/pools/abstract-pool.test.mjs @@ -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 -- 2.53.0