refactor: move message channel property from worker info to node
[poolifier.git] / tests / pools / abstract / abstract-pool.test.js
index af167214644e5bec7b3110aebea546c3fd340238..5c367aa2c0ebf52be17b51dc8f961d70cfabc564 100644 (file)
@@ -1,4 +1,3 @@
-const { MessageChannel } = require('worker_threads')
 const { expect } = require('expect')
 const {
   DynamicClusterPool,
@@ -30,10 +29,12 @@ describe('Abstract pool test suite', () => {
           numberOfWorkers,
           './tests/worker-files/thread/testWorker.js',
           {
-            errorHandler: e => console.error(e)
+            errorHandler: (e) => console.error(e)
           }
         )
-    ).toThrowError('Cannot start a pool from a worker!')
+    ).toThrowError(
+      'Cannot start a pool from a worker with the same type as the pool'
+    )
   })
 
   it('Verify that filePath is checked', () => {
@@ -586,8 +587,7 @@ describe('Abstract pool test suite', () => {
         id: expect.any(Number),
         type: WorkerTypes.thread,
         dynamic: false,
-        ready: true,
-        messageChannel: expect.any(MessageChannel)
+        ready: true
       })
     }
   })
@@ -741,7 +741,7 @@ describe('Abstract pool test suite', () => {
     const promises = new Set()
     let poolFull = 0
     let poolInfo
-    pool.emitter.on(PoolEvents.full, info => {
+    pool.emitter.on(PoolEvents.full, (info) => {
       ++poolFull
       poolInfo = info
     })
@@ -778,7 +778,7 @@ describe('Abstract pool test suite', () => {
     )
     let poolInfo
     let poolReady = 0
-    pool.emitter.on(PoolEvents.ready, info => {
+    pool.emitter.on(PoolEvents.ready, (info) => {
       ++poolReady
       poolInfo = info
     })
@@ -810,7 +810,7 @@ describe('Abstract pool test suite', () => {
     const promises = new Set()
     let poolBusy = 0
     let poolInfo
-    pool.emitter.on(PoolEvents.busy, info => {
+    pool.emitter.on(PoolEvents.busy, (info) => {
       ++poolBusy
       poolInfo = info
     })
@@ -839,11 +839,37 @@ describe('Abstract pool test suite', () => {
     await pool.destroy()
   })
 
-  it('Verify that multiple tasks worker is working', async () => {
+  it('Verify that listTaskFunctions() is working', async () => {
+    const dynamicThreadPool = new DynamicThreadPool(
+      Math.floor(numberOfWorkers / 2),
+      numberOfWorkers,
+      './tests/worker-files/thread/testMultipleTaskFunctionsWorker.js'
+    )
+    await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1)
+    expect(dynamicThreadPool.listTaskFunctions()).toStrictEqual([
+      'default',
+      'jsonIntegerSerialization',
+      'factorial',
+      'fibonacci'
+    ])
+    const fixedClusterPool = new FixedClusterPool(
+      numberOfWorkers,
+      './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js'
+    )
+    await waitPoolEvents(fixedClusterPool, PoolEvents.ready, 1)
+    expect(fixedClusterPool.listTaskFunctions()).toStrictEqual([
+      'default',
+      'jsonIntegerSerialization',
+      'factorial',
+      'fibonacci'
+    ])
+  })
+
+  it('Verify that multiple task functions worker is working', async () => {
     const pool = new DynamicClusterPool(
       Math.floor(numberOfWorkers / 2),
       numberOfWorkers,
-      './tests/worker-files/cluster/testMultiTasksWorker.js'
+      './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js'
     )
     const data = { n: 10 }
     const result0 = await pool.execute(data)