test: improve multiple task functions worker usage test
[poolifier.git] / tests / pools / abstract / abstract-pool.test.js
index e85f112797c3267c79f11bf5d43132b2bbe85ff6..0929adc36a60dcfa0422ad6908041484736ee28c 100644 (file)
@@ -5,21 +5,17 @@ const {
   FixedClusterPool,
   FixedThreadPool,
   PoolEvents,
-  WorkerChoiceStrategies,
   PoolTypes,
+  WorkerChoiceStrategies,
   WorkerTypes
 } = require('../../../lib')
 const { CircularArray } = require('../../../lib/circular-array')
 const { Queue } = require('../../../lib/queue')
+const { version } = require('../../../package.json')
+const { waitPoolEvents } = require('../../test-utils')
 
 describe('Abstract pool test suite', () => {
   const numberOfWorkers = 2
-  class StubPoolWithRemoveAllWorker extends FixedThreadPool {
-    removeAllWorker () {
-      this.workerNodes = []
-      this.promiseResponseMap.clear()
-    }
-  }
   class StubPoolWithIsMain extends FixedThreadPool {
     isMain () {
       return false
@@ -33,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', () => {
@@ -49,6 +47,15 @@ describe('Abstract pool test suite', () => {
     expect(() => new FixedThreadPool(numberOfWorkers, '')).toThrowError(
       expectedError
     )
+    expect(() => new FixedThreadPool(numberOfWorkers, 0)).toThrowError(
+      expectedError
+    )
+    expect(() => new FixedThreadPool(numberOfWorkers, true)).toThrowError(
+      expectedError
+    )
+    expect(
+      () => new FixedThreadPool(numberOfWorkers, './dummyWorker.ts')
+    ).toThrowError(new Error("Cannot find the worker file './dummyWorker.ts'"))
   })
 
   it('Verify that numberOfWorkers is checked', () => {
@@ -79,6 +86,73 @@ describe('Abstract pool test suite', () => {
     )
   })
 
+  it('Verify that dynamic pool sizing is checked', () => {
+    expect(
+      () =>
+        new DynamicClusterPool(
+          1,
+          undefined,
+          './tests/worker-files/cluster/testWorker.js'
+        )
+    ).toThrowError(
+      new TypeError(
+        'Cannot instantiate a dynamic pool without specifying the maximum pool size'
+      )
+    )
+    expect(
+      () =>
+        new DynamicThreadPool(
+          0.5,
+          1,
+          './tests/worker-files/thread/testWorker.js'
+        )
+    ).toThrowError(
+      new TypeError(
+        'Cannot instantiate a pool with a non safe integer number of workers'
+      )
+    )
+    expect(
+      () =>
+        new DynamicClusterPool(
+          0,
+          0.5,
+          './tests/worker-files/cluster/testWorker.js'
+        )
+    ).toThrowError(
+      new TypeError(
+        'Cannot instantiate a dynamic pool with a non safe integer maximum pool size'
+      )
+    )
+    expect(
+      () =>
+        new DynamicThreadPool(2, 1, './tests/worker-files/thread/testWorker.js')
+    ).toThrowError(
+      new RangeError(
+        'Cannot instantiate a dynamic pool with a maximum pool size inferior to the minimum pool size'
+      )
+    )
+    expect(
+      () =>
+        new DynamicClusterPool(
+          1,
+          1,
+          './tests/worker-files/cluster/testWorker.js'
+        )
+    ).toThrowError(
+      new RangeError(
+        'Cannot instantiate a dynamic pool with a minimum pool size equal to the maximum pool size. Use a fixed pool instead'
+      )
+    )
+    expect(
+      () =>
+        new DynamicThreadPool(0, 0, './tests/worker-files/thread/testWorker.js')
+    ).toThrowError(
+      new RangeError(
+        'Cannot instantiate a dynamic pool with a maximum pool size equal to zero'
+      )
+    )
+  })
+
   it('Verify that pool options are checked', async () => {
     let pool = new FixedThreadPool(
       numberOfWorkers,
@@ -93,22 +167,30 @@ describe('Abstract pool test suite', () => {
       WorkerChoiceStrategies.ROUND_ROBIN
     )
     expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
-      medRunTime: false,
-      medWaitTime: false
+      choiceRetries: 6,
+      runTime: { median: false },
+      waitTime: { median: false },
+      elu: { median: false }
+    })
+    expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
+      choiceRetries: 6,
+      runTime: { median: false },
+      waitTime: { median: false },
+      elu: { median: false }
     })
     expect(pool.opts.messageHandler).toBeUndefined()
     expect(pool.opts.errorHandler).toBeUndefined()
     expect(pool.opts.onlineHandler).toBeUndefined()
     expect(pool.opts.exitHandler).toBeUndefined()
     await pool.destroy()
-    const testHandler = () => console.log('test handler executed')
+    const testHandler = () => console.info('test handler executed')
     pool = new FixedThreadPool(
       numberOfWorkers,
       './tests/worker-files/thread/testWorker.js',
       {
         workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED,
         workerChoiceStrategyOptions: {
-          medRunTime: true,
+          runTime: { median: true },
           weights: { 0: 300, 1: 200 }
         },
         enableEvents: false,
@@ -130,7 +212,17 @@ describe('Abstract pool test suite', () => {
       WorkerChoiceStrategies.LEAST_USED
     )
     expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
-      medRunTime: true,
+      choiceRetries: 6,
+      runTime: { median: true },
+      waitTime: { median: false },
+      elu: { median: false },
+      weights: { 0: 300, 1: 200 }
+    })
+    expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
+      choiceRetries: 6,
+      runTime: { median: true },
+      waitTime: { median: false },
+      elu: { median: false },
       weights: { 0: 300, 1: 200 }
     })
     expect(pool.opts.messageHandler).toStrictEqual(testHandler)
@@ -141,6 +233,40 @@ describe('Abstract pool test suite', () => {
   })
 
   it('Verify that pool options are validated', async () => {
+    expect(
+      () =>
+        new FixedThreadPool(
+          numberOfWorkers,
+          './tests/worker-files/thread/testWorker.js',
+          {
+            workerChoiceStrategy: 'invalidStrategy'
+          }
+        )
+    ).toThrowError("Invalid worker choice strategy 'invalidStrategy'")
+    expect(
+      () =>
+        new FixedThreadPool(
+          numberOfWorkers,
+          './tests/worker-files/thread/testWorker.js',
+          {
+            workerChoiceStrategyOptions: { weights: {} }
+          }
+        )
+    ).toThrowError(
+      'Invalid worker choice strategy options: must have a weight for each worker node'
+    )
+    expect(
+      () =>
+        new FixedThreadPool(
+          numberOfWorkers,
+          './tests/worker-files/thread/testWorker.js',
+          {
+            workerChoiceStrategyOptions: { measurement: 'invalidMeasurement' }
+          }
+        )
+    ).toThrowError(
+      "Invalid worker choice strategy options: invalid measurement 'invalidMeasurement'"
+    )
     expect(
       () =>
         new FixedThreadPool(
@@ -158,88 +284,177 @@ describe('Abstract pool test suite', () => {
           numberOfWorkers,
           './tests/worker-files/thread/testWorker.js',
           {
-            workerChoiceStrategy: 'invalidStrategy'
+            enableTasksQueue: true,
+            tasksQueueOptions: 'invalidTasksQueueOptions'
           }
         )
-    ).toThrowError("Invalid worker choice strategy 'invalidStrategy'")
+    ).toThrowError('Invalid tasks queue options: must be a plain object')
     expect(
       () =>
         new FixedThreadPool(
           numberOfWorkers,
           './tests/worker-files/thread/testWorker.js',
           {
-            workerChoiceStrategyOptions: { weights: {} }
+            enableTasksQueue: true,
+            tasksQueueOptions: { concurrency: 0.2 }
           }
         )
-    ).toThrowError(
-      'Invalid worker choice strategy options: must have a weight for each worker node'
-    )
+    ).toThrowError('Invalid worker tasks concurrency: must be an integer')
   })
 
-  it('Verify that worker choice strategy options can be set', async () => {
+  it('Verify that pool worker choice strategy options can be set', async () => {
     const pool = new FixedThreadPool(
       numberOfWorkers,
       './tests/worker-files/thread/testWorker.js',
       { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
     )
     expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
-      medRunTime: false,
-      medWaitTime: false
+      choiceRetries: 6,
+      runTime: { median: false },
+      waitTime: { median: false },
+      elu: { median: false }
+    })
+    expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
+      choiceRetries: 6,
+      runTime: { median: false },
+      waitTime: { median: false },
+      elu: { median: false }
     })
     for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
       .workerChoiceStrategies) {
       expect(workerChoiceStrategy.opts).toStrictEqual({
-        medRunTime: false,
-        medWaitTime: false
+        choiceRetries: 6,
+        runTime: { median: false },
+        waitTime: { median: false },
+        elu: { median: false }
       })
     }
-    expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
-      runTime: true,
-      avgRunTime: true,
-      medRunTime: false,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
-      elu: false
+    expect(
+      pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+    ).toStrictEqual({
+      runTime: {
+        aggregate: true,
+        average: true,
+        median: false
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
+      elu: {
+        aggregate: true,
+        average: true,
+        median: false
+      }
+    })
+    pool.setWorkerChoiceStrategyOptions({
+      runTime: { median: true },
+      elu: { median: true }
     })
-    pool.setWorkerChoiceStrategyOptions({ medRunTime: true })
     expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
-      medRunTime: true
+      choiceRetries: 6,
+      runTime: { median: true },
+      waitTime: { median: false },
+      elu: { median: true }
+    })
+    expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
+      choiceRetries: 6,
+      runTime: { median: true },
+      waitTime: { median: false },
+      elu: { median: true }
     })
     for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
       .workerChoiceStrategies) {
-      expect(workerChoiceStrategy.opts).toStrictEqual({ medRunTime: true })
+      expect(workerChoiceStrategy.opts).toStrictEqual({
+        choiceRetries: 6,
+        runTime: { median: true },
+        waitTime: { median: false },
+        elu: { median: true }
+      })
     }
-    expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
-      runTime: true,
-      avgRunTime: false,
-      medRunTime: true,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
-      elu: false
+    expect(
+      pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+    ).toStrictEqual({
+      runTime: {
+        aggregate: true,
+        average: false,
+        median: true
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
+      elu: {
+        aggregate: true,
+        average: false,
+        median: true
+      }
+    })
+    pool.setWorkerChoiceStrategyOptions({
+      runTime: { median: false },
+      elu: { median: false }
     })
-    pool.setWorkerChoiceStrategyOptions({ medRunTime: false })
     expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
-      medRunTime: false
+      choiceRetries: 6,
+      runTime: { median: false },
+      waitTime: { median: false },
+      elu: { median: false }
+    })
+    expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
+      choiceRetries: 6,
+      runTime: { median: false },
+      waitTime: { median: false },
+      elu: { median: false }
     })
     for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
       .workerChoiceStrategies) {
-      expect(workerChoiceStrategy.opts).toStrictEqual({ medRunTime: false })
+      expect(workerChoiceStrategy.opts).toStrictEqual({
+        choiceRetries: 6,
+        runTime: { median: false },
+        waitTime: { median: false },
+        elu: { median: false }
+      })
     }
-    expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
-      runTime: true,
-      avgRunTime: true,
-      medRunTime: false,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
-      elu: false
+    expect(
+      pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+    ).toStrictEqual({
+      runTime: {
+        aggregate: true,
+        average: true,
+        median: false
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
+      elu: {
+        aggregate: true,
+        average: true,
+        median: false
+      }
     })
+    expect(() =>
+      pool.setWorkerChoiceStrategyOptions('invalidWorkerChoiceStrategyOptions')
+    ).toThrowError(
+      'Invalid worker choice strategy options: must be a plain object'
+    )
+    expect(() =>
+      pool.setWorkerChoiceStrategyOptions({ weights: {} })
+    ).toThrowError(
+      'Invalid worker choice strategy options: must have a weight for each worker node'
+    )
+    expect(() =>
+      pool.setWorkerChoiceStrategyOptions({ measurement: 'invalidMeasurement' })
+    ).toThrowError(
+      "Invalid worker choice strategy options: invalid measurement 'invalidMeasurement'"
+    )
     await pool.destroy()
   })
 
-  it('Verify that tasks queue can be enabled/disabled', async () => {
+  it('Verify that pool tasks queue can be enabled/disabled', async () => {
     const pool = new FixedThreadPool(
       numberOfWorkers,
       './tests/worker-files/thread/testWorker.js'
@@ -258,7 +473,7 @@ describe('Abstract pool test suite', () => {
     await pool.destroy()
   })
 
-  it('Verify that tasks queue options can be set', async () => {
+  it('Verify that pool tasks queue options can be set', async () => {
     const pool = new FixedThreadPool(
       numberOfWorkers,
       './tests/worker-files/thread/testWorker.js',
@@ -267,9 +482,15 @@ describe('Abstract pool test suite', () => {
     expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 1 })
     pool.setTasksQueueOptions({ concurrency: 2 })
     expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 2 })
+    expect(() =>
+      pool.setTasksQueueOptions('invalidTasksQueueOptions')
+    ).toThrowError('Invalid tasks queue options: must be a plain object')
     expect(() => pool.setTasksQueueOptions({ concurrency: 0 })).toThrowError(
       "Invalid worker tasks concurrency '0'"
     )
+    expect(() => pool.setTasksQueueOptions({ concurrency: 0.2 })).toThrowError(
+      'Invalid worker tasks concurrency: must be an integer'
+    )
     await pool.destroy()
   })
 
@@ -279,79 +500,79 @@ describe('Abstract pool test suite', () => {
       './tests/worker-files/thread/testWorker.js'
     )
     expect(pool.info).toStrictEqual({
+      version,
       type: PoolTypes.fixed,
       worker: WorkerTypes.thread,
+      ready: true,
+      strategy: WorkerChoiceStrategies.ROUND_ROBIN,
       minSize: numberOfWorkers,
       maxSize: numberOfWorkers,
       workerNodes: numberOfWorkers,
       idleWorkerNodes: numberOfWorkers,
       busyWorkerNodes: 0,
-      runningTasks: 0,
-      queuedTasks: 0,
-      maxQueuedTasks: 0
+      executedTasks: 0,
+      executingTasks: 0,
+      failedTasks: 0
     })
     await pool.destroy()
     pool = new DynamicClusterPool(
+      Math.floor(numberOfWorkers / 2),
       numberOfWorkers,
-      numberOfWorkers * 2,
-      './tests/worker-files/thread/testWorker.js'
+      './tests/worker-files/cluster/testWorker.js'
     )
     expect(pool.info).toStrictEqual({
+      version,
       type: PoolTypes.dynamic,
       worker: WorkerTypes.cluster,
-      minSize: numberOfWorkers,
-      maxSize: numberOfWorkers * 2,
-      workerNodes: numberOfWorkers,
-      idleWorkerNodes: numberOfWorkers,
+      ready: true,
+      strategy: WorkerChoiceStrategies.ROUND_ROBIN,
+      minSize: Math.floor(numberOfWorkers / 2),
+      maxSize: numberOfWorkers,
+      workerNodes: Math.floor(numberOfWorkers / 2),
+      idleWorkerNodes: Math.floor(numberOfWorkers / 2),
       busyWorkerNodes: 0,
-      runningTasks: 0,
-      queuedTasks: 0,
-      maxQueuedTasks: 0
+      executedTasks: 0,
+      executingTasks: 0,
+      failedTasks: 0
     })
     await pool.destroy()
   })
 
-  it('Simulate worker not found', async () => {
-    const pool = new StubPoolWithRemoveAllWorker(
-      numberOfWorkers,
-      './tests/worker-files/cluster/testWorker.js',
-      {
-        errorHandler: e => console.error(e)
-      }
-    )
-    expect(pool.workerNodes.length).toBe(numberOfWorkers)
-    // Simulate worker not found.
-    pool.removeAllWorker()
-    expect(pool.workerNodes.length).toBe(0)
-    await pool.destroy()
-  })
-
-  it('Verify that worker pool tasks usage are initialized', async () => {
+  it('Verify that pool worker tasks usage are initialized', async () => {
     const pool = new FixedClusterPool(
       numberOfWorkers,
       './tests/worker-files/cluster/testWorker.js'
     )
     for (const workerNode of pool.workerNodes) {
-      expect(workerNode.tasksUsage).toStrictEqual({
-        ran: 0,
-        running: 0,
-        runTime: 0,
-        runTimeHistory: expect.any(CircularArray),
-        avgRunTime: 0,
-        medRunTime: 0,
-        waitTime: 0,
-        waitTimeHistory: expect.any(CircularArray),
-        avgWaitTime: 0,
-        medWaitTime: 0,
-        error: 0,
-        elu: undefined
+      expect(workerNode.usage).toStrictEqual({
+        tasks: {
+          executed: 0,
+          executing: 0,
+          queued: 0,
+          maxQueued: 0,
+          failed: 0
+        },
+        runTime: {
+          history: expect.any(CircularArray)
+        },
+        waitTime: {
+          history: expect.any(CircularArray)
+        },
+        elu: {
+          idle: {
+            history: expect.any(CircularArray)
+          },
+          active: {
+            history: expect.any(CircularArray)
+          }
+        }
       })
     }
     await pool.destroy()
   })
 
-  it('Verify that worker pool tasks queue are initialized', async () => {
-    const pool = new FixedClusterPool(
+  it('Verify that pool worker tasks queue are initialized', async () => {
+    let pool = new FixedClusterPool(
       numberOfWorkers,
       './tests/worker-files/cluster/testWorker.js'
     )
@@ -359,11 +580,52 @@ describe('Abstract pool test suite', () => {
       expect(workerNode.tasksQueue).toBeDefined()
       expect(workerNode.tasksQueue).toBeInstanceOf(Queue)
       expect(workerNode.tasksQueue.size).toBe(0)
+      expect(workerNode.tasksQueue.maxSize).toBe(0)
+    }
+    await pool.destroy()
+    pool = new DynamicThreadPool(
+      Math.floor(numberOfWorkers / 2),
+      numberOfWorkers,
+      './tests/worker-files/thread/testWorker.js'
+    )
+    for (const workerNode of pool.workerNodes) {
+      expect(workerNode.tasksQueue).toBeDefined()
+      expect(workerNode.tasksQueue).toBeInstanceOf(Queue)
+      expect(workerNode.tasksQueue.size).toBe(0)
+      expect(workerNode.tasksQueue.maxSize).toBe(0)
+    }
+  })
+
+  it('Verify that pool worker info are initialized', async () => {
+    let pool = new FixedClusterPool(
+      numberOfWorkers,
+      './tests/worker-files/cluster/testWorker.js'
+    )
+    for (const workerNode of pool.workerNodes) {
+      expect(workerNode.info).toStrictEqual({
+        id: expect.any(Number),
+        type: WorkerTypes.cluster,
+        dynamic: false,
+        ready: true
+      })
     }
     await pool.destroy()
+    pool = new DynamicThreadPool(
+      Math.floor(numberOfWorkers / 2),
+      numberOfWorkers,
+      './tests/worker-files/thread/testWorker.js'
+    )
+    for (const workerNode of pool.workerNodes) {
+      expect(workerNode.info).toStrictEqual({
+        id: expect.any(Number),
+        type: WorkerTypes.thread,
+        dynamic: false,
+        ready: true
+      })
+    }
   })
 
-  it('Verify that worker pool tasks usage are computed', async () => {
+  it('Verify that pool worker tasks usage are computed', async () => {
     const pool = new FixedClusterPool(
       numberOfWorkers,
       './tests/worker-files/cluster/testWorker.js'
@@ -374,44 +636,62 @@ describe('Abstract pool test suite', () => {
       promises.add(pool.execute())
     }
     for (const workerNode of pool.workerNodes) {
-      expect(workerNode.tasksUsage).toStrictEqual({
-        ran: 0,
-        running: maxMultiplier,
-        runTime: 0,
-        runTimeHistory: expect.any(CircularArray),
-        avgRunTime: 0,
-        medRunTime: 0,
-        waitTime: 0,
-        waitTimeHistory: expect.any(CircularArray),
-        avgWaitTime: 0,
-        medWaitTime: 0,
-        error: 0,
-        elu: undefined
+      expect(workerNode.usage).toStrictEqual({
+        tasks: {
+          executed: 0,
+          executing: maxMultiplier,
+          queued: 0,
+          maxQueued: 0,
+          failed: 0
+        },
+        runTime: {
+          history: expect.any(CircularArray)
+        },
+        waitTime: {
+          history: expect.any(CircularArray)
+        },
+        elu: {
+          idle: {
+            history: expect.any(CircularArray)
+          },
+          active: {
+            history: expect.any(CircularArray)
+          }
+        }
       })
     }
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
-      expect(workerNode.tasksUsage).toStrictEqual({
-        ran: maxMultiplier,
-        running: 0,
-        runTime: 0,
-        runTimeHistory: expect.any(CircularArray),
-        avgRunTime: 0,
-        medRunTime: 0,
-        waitTime: 0,
-        waitTimeHistory: expect.any(CircularArray),
-        avgWaitTime: 0,
-        medWaitTime: 0,
-        error: 0,
-        elu: undefined
+      expect(workerNode.usage).toStrictEqual({
+        tasks: {
+          executed: maxMultiplier,
+          executing: 0,
+          queued: 0,
+          maxQueued: 0,
+          failed: 0
+        },
+        runTime: {
+          history: expect.any(CircularArray)
+        },
+        waitTime: {
+          history: expect.any(CircularArray)
+        },
+        elu: {
+          idle: {
+            history: expect.any(CircularArray)
+          },
+          active: {
+            history: expect.any(CircularArray)
+          }
+        }
       })
     }
     await pool.destroy()
   })
 
-  it('Verify that worker pool tasks usage are reset at worker choice strategy change', async () => {
+  it('Verify that pool worker tasks usage are reset at worker choice strategy change', async () => {
     const pool = new DynamicThreadPool(
-      numberOfWorkers,
+      Math.floor(numberOfWorkers / 2),
       numberOfWorkers,
       './tests/worker-files/thread/testWorker.js'
     )
@@ -422,61 +702,136 @@ describe('Abstract pool test suite', () => {
     }
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
-      expect(workerNode.tasksUsage).toStrictEqual({
-        ran: expect.any(Number),
-        running: 0,
-        runTime: 0,
-        runTimeHistory: expect.any(CircularArray),
-        avgRunTime: 0,
-        medRunTime: 0,
-        waitTime: 0,
-        waitTimeHistory: expect.any(CircularArray),
-        avgWaitTime: 0,
-        medWaitTime: 0,
-        error: 0,
-        elu: undefined
+      expect(workerNode.usage).toStrictEqual({
+        tasks: {
+          executed: expect.any(Number),
+          executing: 0,
+          queued: 0,
+          maxQueued: 0,
+          failed: 0
+        },
+        runTime: {
+          history: expect.any(CircularArray)
+        },
+        waitTime: {
+          history: expect.any(CircularArray)
+        },
+        elu: {
+          idle: {
+            history: expect.any(CircularArray)
+          },
+          active: {
+            history: expect.any(CircularArray)
+          }
+        }
       })
-      expect(workerNode.tasksUsage.ran).toBeGreaterThan(0)
-      expect(workerNode.tasksUsage.ran).toBeLessThanOrEqual(maxMultiplier)
+      expect(workerNode.usage.tasks.executed).toBeGreaterThan(0)
+      expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(maxMultiplier)
+      expect(workerNode.usage.runTime.history.length).toBe(0)
+      expect(workerNode.usage.waitTime.history.length).toBe(0)
+      expect(workerNode.usage.elu.idle.history.length).toBe(0)
+      expect(workerNode.usage.elu.active.history.length).toBe(0)
     }
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
     for (const workerNode of pool.workerNodes) {
-      expect(workerNode.tasksUsage).toStrictEqual({
-        ran: 0,
-        running: 0,
-        runTime: 0,
-        runTimeHistory: expect.any(CircularArray),
-        avgRunTime: 0,
-        medRunTime: 0,
-        waitTime: 0,
-        waitTimeHistory: expect.any(CircularArray),
-        avgWaitTime: 0,
-        medWaitTime: 0,
-        error: 0,
-        elu: undefined
+      expect(workerNode.usage).toStrictEqual({
+        tasks: {
+          executed: 0,
+          executing: 0,
+          queued: 0,
+          maxQueued: 0,
+          failed: 0
+        },
+        runTime: {
+          history: expect.any(CircularArray)
+        },
+        waitTime: {
+          history: expect.any(CircularArray)
+        },
+        elu: {
+          idle: {
+            history: expect.any(CircularArray)
+          },
+          active: {
+            history: expect.any(CircularArray)
+          }
+        }
       })
-      expect(workerNode.tasksUsage.runTimeHistory.length).toBe(0)
-      expect(workerNode.tasksUsage.waitTimeHistory.length).toBe(0)
+      expect(workerNode.usage.runTime.history.length).toBe(0)
+      expect(workerNode.usage.waitTime.history.length).toBe(0)
+      expect(workerNode.usage.elu.idle.history.length).toBe(0)
+      expect(workerNode.usage.elu.active.history.length).toBe(0)
     }
     await pool.destroy()
   })
 
   it("Verify that pool event emitter 'full' event can register a callback", async () => {
     const pool = new DynamicThreadPool(
-      numberOfWorkers,
+      Math.floor(numberOfWorkers / 2),
       numberOfWorkers,
       './tests/worker-files/thread/testWorker.js'
     )
     const promises = new Set()
     let poolFull = 0
-    pool.emitter.on(PoolEvents.full, () => ++poolFull)
+    let poolInfo
+    pool.emitter.on(PoolEvents.full, (info) => {
+      ++poolFull
+      poolInfo = info
+    })
     for (let i = 0; i < numberOfWorkers * 2; i++) {
       promises.add(pool.execute())
     }
     await Promise.all(promises)
-    // The `full` 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 * 2 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool with min = max = numberOfWorkers.
-    expect(poolFull).toBe(numberOfWorkers * 2)
+    // The `full` event is triggered when the number of submitted tasks at once reach the maximum number of workers in the dynamic pool.
+    // So in total numberOfWorkers * 2 - 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool with min = (max = numberOfWorkers) / 2.
+    expect(poolFull).toBe(numberOfWorkers * 2 - 1)
+    expect(poolInfo).toStrictEqual({
+      version,
+      type: PoolTypes.dynamic,
+      worker: WorkerTypes.thread,
+      ready: expect.any(Boolean),
+      strategy: WorkerChoiceStrategies.ROUND_ROBIN,
+      minSize: expect.any(Number),
+      maxSize: expect.any(Number),
+      workerNodes: expect.any(Number),
+      idleWorkerNodes: expect.any(Number),
+      busyWorkerNodes: expect.any(Number),
+      executedTasks: expect.any(Number),
+      executingTasks: expect.any(Number),
+      failedTasks: expect.any(Number)
+    })
+    await pool.destroy()
+  })
+
+  it("Verify that pool event emitter 'ready' event can register a callback", async () => {
+    const pool = new DynamicClusterPool(
+      Math.floor(numberOfWorkers / 2),
+      numberOfWorkers,
+      './tests/worker-files/cluster/testWorker.js'
+    )
+    let poolInfo
+    let poolReady = 0
+    pool.emitter.on(PoolEvents.ready, (info) => {
+      ++poolReady
+      poolInfo = info
+    })
+    await waitPoolEvents(pool, PoolEvents.ready, 1)
+    expect(poolReady).toBe(1)
+    expect(poolInfo).toStrictEqual({
+      version,
+      type: PoolTypes.dynamic,
+      worker: WorkerTypes.cluster,
+      ready: true,
+      strategy: WorkerChoiceStrategies.ROUND_ROBIN,
+      minSize: expect.any(Number),
+      maxSize: expect.any(Number),
+      workerNodes: expect.any(Number),
+      idleWorkerNodes: expect.any(Number),
+      busyWorkerNodes: expect.any(Number),
+      executedTasks: expect.any(Number),
+      executingTasks: expect.any(Number),
+      failedTasks: expect.any(Number)
+    })
     await pool.destroy()
   })
 
@@ -487,7 +842,11 @@ describe('Abstract pool test suite', () => {
     )
     const promises = new Set()
     let poolBusy = 0
-    pool.emitter.on(PoolEvents.busy, () => ++poolBusy)
+    let poolInfo
+    pool.emitter.on(PoolEvents.busy, (info) => {
+      ++poolBusy
+      poolInfo = info
+    })
     for (let i = 0; i < numberOfWorkers * 2; i++) {
       promises.add(pool.execute())
     }
@@ -495,23 +854,102 @@ describe('Abstract pool test suite', () => {
     // The `busy` event is triggered when the number of submitted tasks at once reach the number of fixed pool workers.
     // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the fixed pool.
     expect(poolBusy).toBe(numberOfWorkers + 1)
+    expect(poolInfo).toStrictEqual({
+      version,
+      type: PoolTypes.fixed,
+      worker: WorkerTypes.thread,
+      ready: expect.any(Boolean),
+      strategy: WorkerChoiceStrategies.ROUND_ROBIN,
+      minSize: expect.any(Number),
+      maxSize: expect.any(Number),
+      workerNodes: expect.any(Number),
+      idleWorkerNodes: expect.any(Number),
+      busyWorkerNodes: expect.any(Number),
+      executedTasks: expect.any(Number),
+      executingTasks: expect.any(Number),
+      failedTasks: expect.any(Number)
+    })
     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,
-      numberOfWorkers * 2,
-      './tests/worker-files/cluster/testMultiTasksWorker.js'
+      './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js'
     )
     const data = { n: 10 }
     const result0 = await pool.execute(data)
-    expect(result0).toBe(false)
+    expect(result0).toStrictEqual({ ok: 1 })
     const result1 = await pool.execute(data, 'jsonIntegerSerialization')
-    expect(result1).toBe(false)
+    expect(result1).toStrictEqual({ ok: 1 })
     const result2 = await pool.execute(data, 'factorial')
     expect(result2).toBe(3628800)
     const result3 = await pool.execute(data, 'fibonacci')
-    expect(result3).toBe(89)
+    expect(result3).toBe(55)
+    expect(pool.info.executingTasks).toBe(0)
+    expect(pool.info.executedTasks).toBe(4)
+    for (const workerNode of pool.workerNodes) {
+      expect(workerNode.info.taskFunctions).toStrictEqual([
+        'default',
+        'jsonIntegerSerialization',
+        'factorial',
+        'fibonacci'
+      ])
+      expect(workerNode.taskFunctionsUsage.size).toBe(3)
+      for (const name of pool.listTaskFunctions()) {
+        expect(workerNode.getTaskFunctionWorkerUsage(name)).toStrictEqual({
+          tasks: {
+            executed: expect.any(Number),
+            executing: expect.any(Number),
+            failed: 0,
+            queued: 0
+          },
+          runTime: {
+            history: expect.any(CircularArray)
+          },
+          waitTime: {
+            history: expect.any(CircularArray)
+          },
+          elu: {
+            idle: {
+              history: expect.any(CircularArray)
+            },
+            active: {
+              history: expect.any(CircularArray)
+            }
+          }
+        })
+        expect(
+          workerNode.getTaskFunctionWorkerUsage(name).tasks.executing
+        ).toBeGreaterThanOrEqual(0)
+      }
+    }
   })
 })