feat: add new pool options
[poolifier.git] / tests / pools / abstract / worker-node.test.js
index 12e05436bb001dfb07fb1421a1e0be1cececa901..c57ce953fdf826be0811043cc292c340f47b5b8e 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()
         }
       }
     })
@@ -85,17 +100,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()
         }
       }
     })
@@ -134,17 +149,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 +172,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 +195,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()
         }
       }
     })