X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fabstract%2Fworker-node.test.js;h=c670d5bde921d3affadaf97462088962ef08ddab;hb=01bc762f43e8acaa2420246a4dfa0167c26d2e32;hp=12e05436bb001dfb07fb1421a1e0be1cececa901;hpb=75de9f41ce00bec38febd6d82653d3d82f1bb884;p=poolifier.git diff --git a/tests/pools/abstract/worker-node.test.js b/tests/pools/abstract/worker-node.test.js index 12e05436..c670d5bd 100644 --- a/tests/pools/abstract/worker-node.test.js +++ b/tests/pools/abstract/worker-node.test.js @@ -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() } } }) @@ -114,7 +129,7 @@ describe('Worker node test suite', () => { "Cannot get task function worker usage for task function name 'invalidTaskFunction' when task function names list is not yet defined" ) ) - threadWorkerNode.info.taskFunctions = [DEFAULT_TASK_NAME, 'fn1'] + threadWorkerNode.info.taskFunctionNames = [DEFAULT_TASK_NAME, 'fn1'] expect(() => threadWorkerNode.getTaskFunctionWorkerUsage('invalidTaskFunction') ).toThrowError( @@ -122,7 +137,7 @@ describe('Worker node test suite', () => { "Cannot get task function worker usage for task function name 'invalidTaskFunction' when task function names list has less than 3 elements" ) ) - threadWorkerNode.info.taskFunctions = [DEFAULT_TASK_NAME, 'fn1', 'fn2'] + threadWorkerNode.info.taskFunctionNames = [DEFAULT_TASK_NAME, 'fn1', 'fn2'] expect( threadWorkerNode.getTaskFunctionWorkerUsage(DEFAULT_TASK_NAME) ).toStrictEqual({ @@ -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() } } })