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