-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')
'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({
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)
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)
})