+const { MessageChannel } = require('worker_threads')
const { expect } = require('expect')
const {
DynamicClusterPool,
numberOfWorkers,
'./tests/worker-files/thread/testWorker.js',
{
- errorHandler: e => console.error(e)
+ errorHandler: (e) => console.error(e)
}
)
).toThrowError('Cannot start a pool from a worker!')
})
it('Verify that dynamic pool sizing is checked', () => {
+ expect(
+ () =>
+ new DynamicClusterPool(
+ 1,
+ undefined,
+ './tests/worker-files/cluster/testWorker.js'
+ )
+ ).toThrowError(
+ new TypeError(
+ 'Cannot instantiate a dynamic pool without specifying the maximum pool size'
+ )
+ )
+ expect(
+ () =>
+ new DynamicThreadPool(
+ 0.5,
+ 1,
+ './tests/worker-files/thread/testWorker.js'
+ )
+ ).toThrowError(
+ new TypeError(
+ 'Cannot instantiate a pool with a non safe integer number of workers'
+ )
+ )
+ expect(
+ () =>
+ new DynamicClusterPool(
+ 0,
+ 0.5,
+ './tests/worker-files/cluster/testWorker.js'
+ )
+ ).toThrowError(
+ new TypeError(
+ 'Cannot instantiate a dynamic pool with a non safe integer maximum pool size'
+ )
+ )
expect(
() =>
new DynamicThreadPool(2, 1, './tests/worker-files/thread/testWorker.js')
)
expect(
() =>
- new DynamicThreadPool(1, 1, './tests/worker-files/thread/testWorker.js')
+ new DynamicClusterPool(
+ 1,
+ 1,
+ './tests/worker-files/cluster/testWorker.js'
+ )
).toThrowError(
new RangeError(
'Cannot instantiate a dynamic pool with a minimum pool size equal to the maximum pool size. Use a fixed pool instead'
new DynamicThreadPool(0, 0, './tests/worker-files/thread/testWorker.js')
).toThrowError(
new RangeError(
- 'Cannot instantiate a dynamic pool with a pool size equal to zero'
+ 'Cannot instantiate a dynamic pool with a maximum pool size equal to zero'
)
)
})
expect(pool.opts.onlineHandler).toBeUndefined()
expect(pool.opts.exitHandler).toBeUndefined()
await pool.destroy()
- const testHandler = () => console.log('test handler executed')
+ const testHandler = () => console.info('test handler executed')
pool = new FixedThreadPool(
numberOfWorkers,
'./tests/worker-files/thread/testWorker.js',
busyWorkerNodes: 0,
executedTasks: 0,
executingTasks: 0,
- queuedTasks: 0,
- maxQueuedTasks: 0,
failedTasks: 0
})
await pool.destroy()
busyWorkerNodes: 0,
executedTasks: 0,
executingTasks: 0,
- queuedTasks: 0,
- maxQueuedTasks: 0,
failedTasks: 0
})
await pool.destroy()
id: expect.any(Number),
type: WorkerTypes.thread,
dynamic: false,
- ready: true
+ ready: true,
+ messageChannel: expect.any(MessageChannel)
})
}
})
const promises = new Set()
let poolFull = 0
let poolInfo
- pool.emitter.on(PoolEvents.full, info => {
+ pool.emitter.on(PoolEvents.full, (info) => {
++poolFull
poolInfo = info
})
busyWorkerNodes: expect.any(Number),
executedTasks: expect.any(Number),
executingTasks: expect.any(Number),
- queuedTasks: expect.any(Number),
- maxQueuedTasks: expect.any(Number),
failedTasks: expect.any(Number)
})
await pool.destroy()
)
let poolInfo
let poolReady = 0
- pool.emitter.on(PoolEvents.ready, info => {
+ pool.emitter.on(PoolEvents.ready, (info) => {
++poolReady
poolInfo = info
})
busyWorkerNodes: expect.any(Number),
executedTasks: expect.any(Number),
executingTasks: expect.any(Number),
- queuedTasks: expect.any(Number),
- maxQueuedTasks: expect.any(Number),
failedTasks: expect.any(Number)
})
await pool.destroy()
const promises = new Set()
let poolBusy = 0
let poolInfo
- pool.emitter.on(PoolEvents.busy, info => {
+ pool.emitter.on(PoolEvents.busy, (info) => {
++poolBusy
poolInfo = info
})
busyWorkerNodes: expect.any(Number),
executedTasks: expect.any(Number),
executingTasks: expect.any(Number),
- queuedTasks: expect.any(Number),
- maxQueuedTasks: expect.any(Number),
failedTasks: expect.any(Number)
})
await pool.destroy()