test: add test for pool side hasTaskFunction()
[poolifier.git] / tests / pools / abstract / abstract-pool.test.js
index 93e7c256dabaad671a78e53bc1923418bfa6ceef..9dca322ecf036abf8ee77be3dcc7a9bcf7354e1b 100644 (file)
@@ -1243,7 +1243,7 @@ describe('Abstract pool test suite', () => {
     await pool.destroy()
   })
 
-  it('Verify that listTaskFunctions() is working', async () => {
+  it('Verify that listTaskFunctionNames() is working', async () => {
     const dynamicThreadPool = new DynamicThreadPool(
       Math.floor(numberOfWorkers / 2),
       numberOfWorkers,
@@ -1271,6 +1271,36 @@ describe('Abstract pool test suite', () => {
     await fixedClusterPool.destroy()
   })
 
+  it('Verify that hasTaskFunction() 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.hasTaskFunction(DEFAULT_TASK_NAME)).toBe(true)
+    expect(dynamicThreadPool.hasTaskFunction('jsonIntegerSerialization')).toBe(
+      true
+    )
+    expect(dynamicThreadPool.hasTaskFunction('factorial')).toBe(true)
+    expect(dynamicThreadPool.hasTaskFunction('fibonacci')).toBe(true)
+    expect(dynamicThreadPool.hasTaskFunction('unknown')).toBe(false)
+    const fixedClusterPool = new FixedClusterPool(
+      numberOfWorkers,
+      './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js'
+    )
+    await waitPoolEvents(fixedClusterPool, PoolEvents.ready, 1)
+    expect(dynamicThreadPool.hasTaskFunction(DEFAULT_TASK_NAME)).toBe(true)
+    expect(dynamicThreadPool.hasTaskFunction('jsonIntegerSerialization')).toBe(
+      true
+    )
+    expect(dynamicThreadPool.hasTaskFunction('factorial')).toBe(true)
+    expect(dynamicThreadPool.hasTaskFunction('fibonacci')).toBe(true)
+    expect(dynamicThreadPool.hasTaskFunction('unknown')).toBe(false)
+    await dynamicThreadPool.destroy()
+    await fixedClusterPool.destroy()
+  })
+
   it('Verify that multiple task functions worker is working', async () => {
     const pool = new DynamicClusterPool(
       Math.floor(numberOfWorkers / 2),