import { expect } from 'expect'
-import { CircularArray } from '../../lib/circular-array.cjs'
+import { CircularBuffer } from '../../lib/circular-buffer.cjs'
import { WorkerTypes } from '../../lib/index.cjs'
import { WorkerNode } from '../../lib/pools/worker-node.cjs'
import { PriorityQueue } from '../../lib/priority-queue.cjs'
const threadWorkerNode = new WorkerNode(
WorkerTypes.thread,
'./tests/worker-files/thread/testWorker.mjs',
- { tasksQueueBackPressureSize: 12, tasksQueueBucketSize: 6 }
+ {
+ tasksQueueBackPressureSize: 12,
+ tasksQueueBucketSize: 6,
+ tasksQueuePriority: true,
+ }
)
const clusterWorkerNode = new WorkerNode(
WorkerTypes.cluster,
'./tests/worker-files/cluster/testWorker.cjs',
- { tasksQueueBackPressureSize: 12, tasksQueueBucketSize: 6 }
+ {
+ tasksQueueBackPressureSize: 12,
+ tasksQueueBucketSize: 6,
+ tasksQueuePriority: true,
+ }
)
it('Worker node instantiation', () => {
() =>
new WorkerNode(
'invalidWorkerType',
- './tests/worker-files/thread/testWorker.mjs',
- { tasksQueueBackPressureSize: 12 }
+ './tests/worker-files/thread/testWorker.mjs'
)
).toThrow(
new TypeError(
)
).toThrow(
new TypeError(
- 'Cannot construct a worker node with invalid options: must be a plain object'
+ 'Cannot construct a worker node with invalid worker node options: must be a plain object'
)
)
expect(
WorkerTypes.thread,
'./tests/worker-files/thread/testWorker.mjs',
{
- tasksQueueBackPressureSize: 12
+ tasksQueueBackPressureSize: 12,
}
)
).toThrow(
'./tests/worker-files/thread/testWorker.mjs',
{
tasksQueueBackPressureSize: 12,
- tasksQueueBucketSize: 'invalidTasksQueueBucketSize'
+ tasksQueueBucketSize: 'invalidTasksQueueBucketSize',
}
)
).toThrow(
'Cannot construct a worker node with a tasks queue bucket size option that is not a positive integer'
)
)
+ expect(
+ () =>
+ new WorkerNode(
+ WorkerTypes.thread,
+ './tests/worker-files/thread/testWorker.mjs',
+ {
+ tasksQueueBackPressureSize: 12,
+ tasksQueueBucketSize: 6,
+ }
+ )
+ ).toThrow(
+ new RangeError(
+ 'Cannot construct a worker node without a tasks queue priority option'
+ )
+ )
+ expect(
+ () =>
+ new WorkerNode(
+ WorkerTypes.thread,
+ './tests/worker-files/thread/testWorker.mjs',
+ {
+ tasksQueueBackPressureSize: 12,
+ tasksQueueBucketSize: 6,
+ tasksQueuePriority: 'invalidTasksQueuePriority',
+ }
+ )
+ ).toThrow(
+ new RangeError(
+ 'Cannot construct a worker node with a tasks queue priority option that is not a boolean'
+ )
+ )
expect(threadWorkerNode).toBeInstanceOf(WorkerNode)
expect(threadWorkerNode.worker).toBeInstanceOf(ThreadWorker)
expect(threadWorkerNode.info).toStrictEqual({
dynamic: false,
ready: false,
stealing: false,
- backPressure: false
+ backPressure: false,
})
expect(threadWorkerNode.usage).toStrictEqual({
tasks: {
maxQueued: 0,
sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ failed: 0,
},
runTime: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
waitTime: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
elu: {
idle: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
active: {
- history: new CircularArray()
- }
- }
+ history: expect.any(CircularBuffer),
+ },
+ },
})
expect(threadWorkerNode.messageChannel).toBeInstanceOf(MessageChannel)
expect(threadWorkerNode.tasksQueueBackPressureSize).toBe(12)
expect(threadWorkerNode.tasksQueue).toBeInstanceOf(PriorityQueue)
expect(threadWorkerNode.tasksQueue.size).toBe(0)
- expect(threadWorkerNode.tasksQueue.k).toBe(6)
+ expect(threadWorkerNode.tasksQueue.bucketSize).toBe(6)
+ expect(threadWorkerNode.tasksQueue.enablePriority).toBe(true)
expect(threadWorkerNode.tasksQueueSize()).toBe(
threadWorkerNode.tasksQueue.size
)
dynamic: false,
ready: false,
stealing: false,
- backPressure: false
+ backPressure: false,
})
expect(clusterWorkerNode.usage).toStrictEqual({
tasks: {
maxQueued: 0,
sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ failed: 0,
},
runTime: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
waitTime: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
elu: {
idle: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
active: {
- history: new CircularArray()
- }
- }
+ history: expect.any(CircularBuffer),
+ },
+ },
})
expect(clusterWorkerNode.messageChannel).toBeUndefined()
expect(clusterWorkerNode.tasksQueueBackPressureSize).toBe(12)
expect(clusterWorkerNode.tasksQueue).toBeInstanceOf(PriorityQueue)
expect(clusterWorkerNode.tasksQueue.size).toBe(0)
- expect(clusterWorkerNode.tasksQueue.k).toBe(6)
+ expect(clusterWorkerNode.tasksQueue.bucketSize).toBe(6)
+ expect(clusterWorkerNode.tasksQueue.enablePriority).toBe(true)
expect(clusterWorkerNode.tasksQueueSize()).toBe(
clusterWorkerNode.tasksQueue.size
)
)
threadWorkerNode.info.taskFunctionsProperties = [
{ name: DEFAULT_TASK_NAME },
- { name: 'fn1' }
+ { name: 'fn1' },
]
expect(() =>
threadWorkerNode.getTaskFunctionWorkerUsage('invalidTaskFunction')
threadWorkerNode.info.taskFunctionsProperties = [
{ name: DEFAULT_TASK_NAME },
{ name: 'fn1' },
- { name: 'fn2' }
+ { name: 'fn2' },
]
expect(
threadWorkerNode.getTaskFunctionWorkerUsage(DEFAULT_TASK_NAME)
queued: 0,
sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ failed: 0,
},
runTime: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
waitTime: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
elu: {
idle: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
active: {
- history: new CircularArray()
- }
- }
+ history: expect.any(CircularBuffer),
+ },
+ },
})
expect(threadWorkerNode.getTaskFunctionWorkerUsage('fn1')).toStrictEqual({
tasks: {
queued: 0,
sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ failed: 0,
},
runTime: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
waitTime: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
elu: {
idle: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
active: {
- history: new CircularArray()
- }
- }
+ history: expect.any(CircularBuffer),
+ },
+ },
})
expect(threadWorkerNode.getTaskFunctionWorkerUsage('fn2')).toStrictEqual({
tasks: {
queued: 0,
sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ failed: 0,
},
runTime: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
waitTime: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
elu: {
idle: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
active: {
- history: new CircularArray()
- }
- }
+ history: expect.any(CircularBuffer),
+ },
+ },
})
expect(threadWorkerNode.taskFunctionsUsage.size).toBe(2)
})
expect(threadWorkerNode.info.taskFunctionsProperties).toStrictEqual([
{ name: DEFAULT_TASK_NAME },
{ name: 'fn1' },
- { name: 'fn2' }
+ { name: 'fn2' },
])
expect(threadWorkerNode.taskFunctionsUsage.size).toBe(2)
expect(