refactor: split TestUtils class into arrow functions
[poolifier.git] / tests / pools / cluster / dynamic.test.js
index ed6340830ad4de242772fa3f8078974bf4d10968..78bdc2149740b1acc02bff301f7f75bb64e7627b 100644 (file)
@@ -1,7 +1,7 @@
 const { expect } = require('expect')
 const { DynamicClusterPool, PoolEvents } = require('../../../lib')
 const { WorkerFunctions } = require('../../test-types')
-const TestUtils = require('../../test-utils')
+const { sleep, waitWorkerEvents } = require('../../test-utils')
 
 describe('Dynamic cluster pool test suite', () => {
   const min = 1
@@ -37,11 +37,7 @@ describe('Dynamic cluster pool test suite', () => {
     // The `busy` event is triggered when the number of submitted tasks at once reach the max number of workers in the dynamic pool.
     // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool.
     expect(poolBusy).toBe(max + 1)
-    const numberOfExitEvents = await TestUtils.waitWorkerEvents(
-      pool,
-      'exit',
-      max - min
-    )
+    const numberOfExitEvents = await waitWorkerEvents(pool, 'exit', max - min)
     expect(numberOfExitEvents).toBe(max - min)
   })
 
@@ -51,18 +47,18 @@ describe('Dynamic cluster pool test suite', () => {
       pool.execute()
     }
     expect(pool.workerNodes.length).toBeGreaterThan(min)
-    await TestUtils.waitWorkerEvents(pool, 'exit', max - min)
+    await waitWorkerEvents(pool, 'exit', max - min)
     expect(pool.workerNodes.length).toBe(min)
     for (let i = 0; i < max * 2; i++) {
       pool.execute()
     }
     expect(pool.workerNodes.length).toBeGreaterThan(min)
-    await TestUtils.waitWorkerEvents(pool, 'exit', max - min)
+    await waitWorkerEvents(pool, 'exit', max - min)
     expect(pool.workerNodes.length).toBe(min)
   })
 
   it('Shutdown test', async () => {
-    const exitPromise = TestUtils.waitWorkerEvents(pool, 'exit', min)
+    const exitPromise = waitWorkerEvents(pool, 'exit', min)
     await pool.destroy()
     const numberOfExitEvents = await exitPromise
     expect(numberOfExitEvents).toBe(min)
@@ -102,7 +98,7 @@ describe('Dynamic cluster pool test suite', () => {
       longRunningPool.execute()
     }
     expect(longRunningPool.workerNodes.length).toBe(max)
-    await TestUtils.waitWorkerEvents(longRunningPool, 'exit', max - min)
+    await waitWorkerEvents(longRunningPool, 'exit', max - min)
     expect(longRunningPool.workerNodes.length).toBe(min)
     expect(
       longRunningPool.workerChoiceStrategyContext.workerChoiceStrategies.get(
@@ -129,7 +125,7 @@ describe('Dynamic cluster pool test suite', () => {
       longRunningPool.execute()
     }
     expect(longRunningPool.workerNodes.length).toBe(max)
-    await TestUtils.sleep(1500)
+    await sleep(1500)
     // Here we expect the workerNodes to be at the max size since the task is still executing
     expect(longRunningPool.workerNodes.length).toBe(max)
     // We need to clean up the resources after our test