From: Jérôme Benoit Date: Wed, 31 Jul 2024 12:33:14 +0000 (+0200) Subject: test: cleanup fixed pool tests setup and teardown X-Git-Tag: v4.2.0~35 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=311c5bdbcf67f99f8cc8f066ecd92fc42a670f8d;p=poolifier.git test: cleanup fixed pool tests setup and teardown Signed-off-by: Jérôme Benoit --- 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()