X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fabstract%2Fworker-node.test.js;h=45b97c1c9251086a9d9154e01efc1b37fa9dd74b;hb=4e434375b0d3667a4389e222fcac4ec87443b78a;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..45b97c1c 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() } } }) @@ -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() } } })