From 311c5bdbcf67f99f8cc8f066ecd92fc42a670f8d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 31 Jul 2024 14:33:14 +0200 Subject: [PATCH] test: cleanup fixed pool tests setup and teardown MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- tests/pools/cluster/fixed.test.mjs | 98 ++++++++++++++++-------------- tests/pools/thread/fixed.test.mjs | 98 ++++++++++++++++-------------- 2 files changed, 102 insertions(+), 94 deletions(-) diff --git a/tests/pools/cluster/fixed.test.mjs b/tests/pools/cluster/fixed.test.mjs index a78a4509..c4279236 100644 --- a/tests/pools/cluster/fixed.test.mjs +++ b/tests/pools/cluster/fixed.test.mjs @@ -10,54 +10,58 @@ import { waitPoolEvents, waitWorkerEvents } from '../../test-utils.cjs' describe('Fixed cluster pool test suite', () => { const numberOfWorkers = 8 const tasksConcurrency = 2 - const pool = new FixedClusterPool( - numberOfWorkers, - './tests/worker-files/cluster/testWorker.cjs', - { - errorHandler: e => console.error(e), - } - ) - const queuePool = new FixedClusterPool( - numberOfWorkers, - './tests/worker-files/cluster/testWorker.cjs', - { - enableTasksQueue: true, - tasksQueueOptions: { - concurrency: tasksConcurrency, - }, - errorHandler: e => console.error(e), - } - ) - const emptyPool = new FixedClusterPool( - numberOfWorkers, - './tests/worker-files/cluster/emptyWorker.cjs', - { exitHandler: () => console.info('empty pool worker exited') } - ) - const echoPool = new FixedClusterPool( - numberOfWorkers, - './tests/worker-files/cluster/echoWorker.cjs' - ) - const errorPool = new FixedClusterPool( - numberOfWorkers, - './tests/worker-files/cluster/errorWorker.cjs', - { - errorHandler: e => console.error(e), - } - ) - const asyncErrorPool = new FixedClusterPool( - numberOfWorkers, - './tests/worker-files/cluster/asyncErrorWorker.cjs', - { - errorHandler: e => console.error(e), - } - ) - const asyncPool = new FixedClusterPool( - numberOfWorkers, - './tests/worker-files/cluster/asyncWorker.cjs' - ) + let pool, queuePool, emptyPool, echoPool, errorPool, asyncErrorPool, asyncPool - after('Destroy all pools', async () => { - // We need to clean up the resources after our test + before('Create pools', () => { + pool = new FixedClusterPool( + numberOfWorkers, + './tests/worker-files/cluster/testWorker.cjs', + { + errorHandler: e => console.error(e), + } + ) + queuePool = new FixedClusterPool( + numberOfWorkers, + './tests/worker-files/cluster/testWorker.cjs', + { + enableTasksQueue: true, + tasksQueueOptions: { + concurrency: tasksConcurrency, + }, + errorHandler: e => console.error(e), + } + ) + emptyPool = new FixedClusterPool( + numberOfWorkers, + './tests/worker-files/cluster/emptyWorker.cjs', + { exitHandler: () => console.info('empty pool worker exited') } + ) + echoPool = new FixedClusterPool( + numberOfWorkers, + './tests/worker-files/cluster/echoWorker.cjs' + ) + errorPool = new FixedClusterPool( + numberOfWorkers, + './tests/worker-files/cluster/errorWorker.cjs', + { + errorHandler: e => console.error(e), + } + ) + asyncErrorPool = new FixedClusterPool( + numberOfWorkers, + './tests/worker-files/cluster/asyncErrorWorker.cjs', + { + errorHandler: e => console.error(e), + } + ) + asyncPool = new FixedClusterPool( + numberOfWorkers, + './tests/worker-files/cluster/asyncWorker.cjs' + ) + }) + + after('Destroy pools', async () => { + // We need to clean up the resources after our tests await echoPool.destroy() await asyncPool.destroy() await errorPool.destroy() diff --git a/tests/pools/thread/fixed.test.mjs b/tests/pools/thread/fixed.test.mjs index 044eb808..e78ed180 100644 --- a/tests/pools/thread/fixed.test.mjs +++ b/tests/pools/thread/fixed.test.mjs @@ -8,54 +8,58 @@ import { waitPoolEvents, waitWorkerEvents } from '../../test-utils.cjs' describe('Fixed thread pool test suite', () => { const numberOfThreads = 6 const tasksConcurrency = 2 - const pool = new FixedThreadPool( - numberOfThreads, - './tests/worker-files/thread/testWorker.mjs', - { - errorHandler: e => console.error(e), - } - ) - const queuePool = new FixedThreadPool( - numberOfThreads, - './tests/worker-files/thread/testWorker.mjs', - { - enableTasksQueue: true, - tasksQueueOptions: { - concurrency: tasksConcurrency, - }, - errorHandler: e => console.error(e), - } - ) - const emptyPool = new FixedThreadPool( - numberOfThreads, - './tests/worker-files/thread/emptyWorker.mjs', - { exitHandler: () => console.info('empty pool worker exited') } - ) - const echoPool = new FixedThreadPool( - numberOfThreads, - './tests/worker-files/thread/echoWorker.mjs' - ) - const errorPool = new FixedThreadPool( - numberOfThreads, - './tests/worker-files/thread/errorWorker.mjs', - { - errorHandler: e => console.error(e), - } - ) - const asyncErrorPool = new FixedThreadPool( - numberOfThreads, - './tests/worker-files/thread/asyncErrorWorker.mjs', - { - errorHandler: e => console.error(e), - } - ) - const asyncPool = new FixedThreadPool( - numberOfThreads, - './tests/worker-files/thread/asyncWorker.mjs' - ) + let pool, queuePool, emptyPool, echoPool, errorPool, asyncErrorPool, asyncPool - after('Destroy all pools', async () => { - // We need to clean up the resources after our test + before('Create pools', () => { + pool = new FixedThreadPool( + numberOfThreads, + './tests/worker-files/thread/testWorker.mjs', + { + errorHandler: e => console.error(e), + } + ) + queuePool = new FixedThreadPool( + numberOfThreads, + './tests/worker-files/thread/testWorker.mjs', + { + enableTasksQueue: true, + tasksQueueOptions: { + concurrency: tasksConcurrency, + }, + errorHandler: e => console.error(e), + } + ) + emptyPool = new FixedThreadPool( + numberOfThreads, + './tests/worker-files/thread/emptyWorker.mjs', + { exitHandler: () => console.info('empty pool worker exited') } + ) + echoPool = new FixedThreadPool( + numberOfThreads, + './tests/worker-files/thread/echoWorker.mjs' + ) + errorPool = new FixedThreadPool( + numberOfThreads, + './tests/worker-files/thread/errorWorker.mjs', + { + errorHandler: e => console.error(e), + } + ) + asyncErrorPool = new FixedThreadPool( + numberOfThreads, + './tests/worker-files/thread/asyncErrorWorker.mjs', + { + errorHandler: e => console.error(e), + } + ) + asyncPool = new FixedThreadPool( + numberOfThreads, + './tests/worker-files/thread/asyncWorker.mjs' + ) + }) + + after('Destroy pools', async () => { + // We need to clean up the resources after our tests await echoPool.destroy() await asyncPool.destroy() await errorPool.destroy() -- 2.34.1