docs: fixlet to benchmarks/README.md
[poolifier.git] / tests / pools / abstract / worker-node.test.js
index 12e05436bb001dfb07fb1421a1e0be1cececa901..45b97c1c9251086a9d9154e01efc1b37fa9dd74b 100644 (file)
@@ -1,5 +1,5 @@
-const { MessageChannel, Worker } = require('worker_threads')
-const cluster = require('cluster')
+const { MessageChannel, Worker } = require('node:worker_threads')
+const cluster = require('node:cluster')
 const { expect } = require('expect')
 const { WorkerNode } = require('../../../lib/pools/worker-node')
 const { WorkerTypes } = require('../../../lib')
@@ -29,6 +29,21 @@ describe('Worker node test suite', () => {
         'Cannot construct a worker node with a tasks queue back pressure size that is not an integer'
       )
     )
+    expect(() => new WorkerNode(threadWorker, 0.2)).toThrowError(
+      new TypeError(
+        'Cannot construct a worker node with a tasks queue back pressure size that is not an integer'
+      )
+    )
+    expect(() => new WorkerNode(threadWorker, 0)).toThrowError(
+      new RangeError(
+        'Cannot construct a worker node with a tasks queue back pressure size that is not a positive integer'
+      )
+    )
+    expect(() => new WorkerNode(threadWorker, -1)).toThrowError(
+      new RangeError(
+        'Cannot construct a worker node with a tasks queue back pressure size that is not a positive integer'
+      )
+    )
     expect(threadWorkerNode).toBeInstanceOf(WorkerNode)
     expect(threadWorkerNode.worker).toBe(threadWorker)
     expect(threadWorkerNode.info).toStrictEqual({
@@ -47,17 +62,17 @@ describe('Worker node 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()
         }
       }
     })
@@ -65,6 +80,11 @@ describe('Worker node test suite', () => {
     expect(threadWorkerNode.tasksQueueBackPressureSize).toBe(12)
     expect(threadWorkerNode.tasksQueue).toBeInstanceOf(Deque)
     expect(threadWorkerNode.tasksQueue.size).toBe(0)
+    expect(threadWorkerNode.tasksQueueSize()).toBe(
+      threadWorkerNode.tasksQueue.size
+    )
+    expect(threadWorkerNode.onBackPressureStarted).toBe(false)
+    expect(threadWorkerNode.onEmptyQueueCount).toBe(0)
     expect(threadWorkerNode.taskFunctionsUsage).toBeInstanceOf(Map)
 
     expect(clusterWorkerNode).toBeInstanceOf(WorkerNode)
@@ -85,17 +105,17 @@ describe('Worker node 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()
         }
       }
     })
@@ -103,6 +123,11 @@ describe('Worker node test suite', () => {
     expect(clusterWorkerNode.tasksQueueBackPressureSize).toBe(12)
     expect(clusterWorkerNode.tasksQueue).toBeInstanceOf(Deque)
     expect(clusterWorkerNode.tasksQueue.size).toBe(0)
+    expect(clusterWorkerNode.tasksQueueSize()).toBe(
+      clusterWorkerNode.tasksQueue.size
+    )
+    expect(clusterWorkerNode.onBackPressureStarted).toBe(false)
+    expect(clusterWorkerNode.onEmptyQueueCount).toBe(0)
     expect(clusterWorkerNode.taskFunctionsUsage).toBeInstanceOf(Map)
   })
 
@@ -134,17 +159,17 @@ describe('Worker node 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()
         }
       }
     })
@@ -157,17 +182,17 @@ describe('Worker node 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()
         }
       }
     })
@@ -180,17 +205,17 @@ describe('Worker node 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()
         }
       }
     })