test: cleanup fixed pool tests setup and teardown
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 31 Jul 2024 12:33:14 +0000 (14:33 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 31 Jul 2024 12:33:14 +0000 (14:33 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
tests/pools/cluster/fixed.test.mjs
tests/pools/thread/fixed.test.mjs

index a78a4509fb263b987d08e5cb0e9d1e7f6d607070..c42792368d82c4223f6e822489efd108a8b288c7 100644 (file)
@@ -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()
index 044eb8083df9a40c8a241c6c76e042bac5546f67..e78ed180b290963d30f6f2ce7b1e908b8b6383f9 100644 (file)
@@ -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()