fix: fix pool sizing in examples
[poolifier.git] / tests / pools / thread / dynamic.test.js
index 1de664463edf589f50c0a46ed58bb159209a37fd..6e6142b715b802493928b8d5d7031ecaf1ebe76f 100644 (file)
@@ -1,6 +1,6 @@
 const { expect } = require('expect')
 const { DynamicThreadPool, PoolEvents } = require('../../../lib')
-const { WorkerFunctions } = require('../../test-types')
+const { TaskFunctions } = require('../../test-types')
 const { sleep, waitWorkerEvents } = require('../../test-utils')
 
 describe('Dynamic thread pool test suite', () => {
@@ -11,17 +11,17 @@ describe('Dynamic thread pool test suite', () => {
     max,
     './tests/worker-files/thread/testWorker.js',
     {
-      errorHandler: e => console.error(e)
+      errorHandler: (e) => console.error(e)
     }
   )
 
   it('Verify that the function is executed in a worker thread', async () => {
     let result = await pool.execute({
-      function: WorkerFunctions.fibonacci
+      function: TaskFunctions.fibonacci
     })
     expect(result).toBe(75025)
     result = await pool.execute({
-      function: WorkerFunctions.factorial
+      function: TaskFunctions.factorial
     })
     expect(result).toBe(9.33262154439441e157)
   })
@@ -77,7 +77,7 @@ describe('Dynamic thread pool test suite', () => {
       './tests/worker-files/thread/testWorker.js'
     )
     const res = await pool1.execute()
-    expect(res).toBe(false)
+    expect(res).toStrictEqual({ ok: 1 })
     // We need to clean up the resources after our test
     await pool1.destroy()
   })
@@ -88,9 +88,9 @@ describe('Dynamic thread pool test suite', () => {
       max,
       './tests/worker-files/thread/longRunningWorkerHardBehavior.js',
       {
-        errorHandler: e => console.error(e),
-        onlineHandler: () => console.log('long executing worker is online'),
-        exitHandler: () => console.log('long executing worker exited')
+        errorHandler: (e) => console.error(e),
+        onlineHandler: () => console.info('long executing worker is online'),
+        exitHandler: () => console.info('long executing worker exited')
       }
     )
     expect(longRunningPool.workerNodes.length).toBe(min)
@@ -103,7 +103,7 @@ describe('Dynamic thread pool test suite', () => {
     expect(
       longRunningPool.workerChoiceStrategyContext.workerChoiceStrategies.get(
         longRunningPool.workerChoiceStrategyContext.workerChoiceStrategy
-      ).nextWorkerNodeId
+      ).nextWorkerNodeKey
     ).toBeLessThan(longRunningPool.workerNodes.length)
     // We need to clean up the resources after our test
     await longRunningPool.destroy()
@@ -115,9 +115,9 @@ describe('Dynamic thread pool test suite', () => {
       max,
       './tests/worker-files/thread/longRunningWorkerSoftBehavior.js',
       {
-        errorHandler: e => console.error(e),
-        onlineHandler: () => console.log('long executing worker is online'),
-        exitHandler: () => console.log('long executing worker exited')
+        errorHandler: (e) => console.error(e),
+        onlineHandler: () => console.info('long executing worker is online'),
+        exitHandler: () => console.info('long executing worker exited')
       }
     )
     expect(longRunningPool.workerNodes.length).toBe(min)
@@ -125,7 +125,7 @@ describe('Dynamic thread pool test suite', () => {
       longRunningPool.execute()
     }
     expect(longRunningPool.workerNodes.length).toBe(max)
-    await sleep(1500)
+    await sleep(1000)
     // 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