Merge dependabot/npm_and_yarn/examples/typescript/http-server-pool/fastify-cluster...
[poolifier.git] / tests / pools / abstract / abstract-pool.test.js
index ba9fc4f71825a084881cd86e5a401bd6de80cbda..bedb1c6c42a9121697990121185c049c26ed87a4 100644 (file)
@@ -1,3 +1,4 @@
+const { EventEmitter } = require('node:events')
 const { expect } = require('expect')
 const sinon = require('sinon')
 const {
@@ -35,7 +36,7 @@ describe('Abstract pool test suite', () => {
           numberOfWorkers,
           './tests/worker-files/thread/testWorker.js',
           {
-            errorHandler: (e) => console.error(e)
+            errorHandler: e => console.error(e)
           }
         )
     ).toThrowError(
@@ -178,7 +179,7 @@ describe('Abstract pool test suite', () => {
       numberOfWorkers,
       './tests/worker-files/thread/testWorker.js'
     )
-    expect(pool.emitter).toBeDefined()
+    expect(pool.emitter).toBeInstanceOf(EventEmitter)
     expect(pool.opts.enableEvents).toBe(true)
     expect(pool.opts.restartWorkerOnError).toBe(true)
     expect(pool.opts.enableTasksQueue).toBe(false)
@@ -776,17 +777,17 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          history: expect.any(CircularArray)
+          history: new CircularArray()
         },
         waitTime: {
-          history: expect.any(CircularArray)
+          history: new CircularArray()
         },
         elu: {
           idle: {
-            history: expect.any(CircularArray)
+            history: new CircularArray()
           },
           active: {
-            history: expect.any(CircularArray)
+            history: new CircularArray()
           }
         }
       })
@@ -1027,7 +1028,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
     })
@@ -1059,7 +1060,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
     })
@@ -1097,7 +1098,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
     })
@@ -1136,7 +1137,7 @@ describe('Abstract pool test suite', () => {
     const promises = new Set()
     let poolBackPressure = 0
     let poolInfo
-    pool.emitter.on(PoolEvents.backPressure, (info) => {
+    pool.emitter.on(PoolEvents.backPressure, info => {
       ++poolBackPressure
       poolInfo = info
     })
@@ -1225,7 +1226,7 @@ describe('Abstract pool test suite', () => {
         expect(workerNode.getTaskFunctionWorkerUsage(name)).toStrictEqual({
           tasks: {
             executed: expect.any(Number),
-            executing: expect.any(Number),
+            executing: 0,
             failed: 0,
             queued: 0,
             stolen: 0
@@ -1246,9 +1247,14 @@ describe('Abstract pool test suite', () => {
           }
         })
         expect(
-          workerNode.getTaskFunctionWorkerUsage(name).tasks.executing
-        ).toBeGreaterThanOrEqual(0)
+          workerNode.getTaskFunctionWorkerUsage(name).tasks.executed
+        ).toBeGreaterThan(0)
       }
+      expect(
+        workerNode.getTaskFunctionWorkerUsage(DEFAULT_TASK_NAME)
+      ).toStrictEqual(
+        workerNode.getTaskFunctionWorkerUsage(workerNode.info.taskFunctions[1])
+      )
     }
     await pool.destroy()
   })