numberOfWorkers,
'./tests/worker-files/cluster/testWorker.js'
)
+ expect(pool.emitter.eventNames()).toStrictEqual([])
let poolInfo
let poolReady = 0
pool.emitter.on(PoolEvents.ready, info => {
poolInfo = info
})
await waitPoolEvents(pool, PoolEvents.ready, 1)
+ expect(pool.emitter.eventNames()).toStrictEqual([PoolEvents.ready])
expect(poolReady).toBe(1)
expect(poolInfo).toStrictEqual({
version,
numberOfWorkers,
'./tests/worker-files/thread/testWorker.js'
)
+ expect(pool.emitter.eventNames()).toStrictEqual([])
const promises = new Set()
let poolBusy = 0
let poolInfo
++poolBusy
poolInfo = info
})
+ expect(pool.emitter.eventNames()).toStrictEqual([PoolEvents.busy])
for (let i = 0; i < numberOfWorkers * 2; i++) {
promises.add(pool.execute())
}
numberOfWorkers,
'./tests/worker-files/thread/testWorker.js'
)
+ expect(pool.emitter.eventNames()).toStrictEqual([])
const promises = new Set()
let poolFull = 0
let poolInfo
++poolFull
poolInfo = info
})
+ expect(pool.emitter.eventNames()).toStrictEqual([PoolEvents.full])
for (let i = 0; i < numberOfWorkers * 2; i++) {
promises.add(pool.execute())
}
}
)
sinon.stub(pool, 'hasBackPressure').returns(true)
+ expect(pool.emitter.eventNames()).toStrictEqual([])
const promises = new Set()
let poolBackPressure = 0
let poolInfo
++poolBackPressure
poolInfo = info
})
+ expect(pool.emitter.eventNames()).toStrictEqual([PoolEvents.backPressure])
for (let i = 0; i < numberOfWorkers + 1; i++) {
promises.add(pool.execute())
}
it('Shutdown test', async () => {
const exitPromise = waitWorkerEvents(pool, 'exit', min)
+ expect(pool.emitter.eventNames()).toStrictEqual([PoolEvents.busy])
let poolDestroy = 0
pool.emitter.on(PoolEvents.destroy, () => ++poolDestroy)
+ expect(pool.emitter.eventNames()).toStrictEqual([
+ PoolEvents.busy,
+ PoolEvents.destroy
+ ])
await pool.destroy()
const numberOfExitEvents = await exitPromise
expect(pool.started).toBe(false)
errorHandler: e => console.error(e)
}
)
+ expect(pool.emitter.eventNames()).toStrictEqual([])
let poolReady = 0
pool.emitter.on(PoolEvents.ready, () => ++poolReady)
await waitPoolEvents(pool, PoolEvents.ready, 1)
+ expect(pool.emitter.eventNames()).toStrictEqual([PoolEvents.ready])
expect(poolReady).toBe(1)
await pool.destroy()
})
it("Verify that 'busy' event is emitted", async () => {
+ expect(pool.emitter.eventNames()).toStrictEqual([])
const promises = new Set()
let poolBusy = 0
pool.emitter.on(PoolEvents.busy, () => ++poolBusy)
+ expect(pool.emitter.eventNames()).toStrictEqual([PoolEvents.busy])
for (let i = 0; i < numberOfWorkers * 2; i++) {
promises.add(pool.execute())
}
it('Verify that error handling is working properly:sync', async () => {
const data = { f: 10 }
+ expect(errorPool.emitter.eventNames()).toStrictEqual([])
let taskError
errorPool.emitter.on(PoolEvents.taskError, e => {
taskError = e
})
+ expect(errorPool.emitter.eventNames()).toStrictEqual([PoolEvents.taskError])
let inError
try {
await errorPool.execute(data)
it('Verify that error handling is working properly:async', async () => {
const data = { f: 10 }
+ expect(asyncErrorPool.emitter.eventNames()).toStrictEqual([])
let taskError
asyncErrorPool.emitter.on(PoolEvents.taskError, e => {
taskError = e
})
+ expect(asyncErrorPool.emitter.eventNames()).toStrictEqual([
+ PoolEvents.taskError
+ ])
let inError
try {
await asyncErrorPool.execute(data)
it('Shutdown test', async () => {
const exitPromise = waitWorkerEvents(pool, 'exit', numberOfWorkers)
+ expect(pool.emitter.eventNames()).toStrictEqual([PoolEvents.busy])
let poolDestroy = 0
pool.emitter.on(PoolEvents.destroy, () => ++poolDestroy)
+ expect(pool.emitter.eventNames()).toStrictEqual([
+ PoolEvents.busy,
+ PoolEvents.destroy
+ ])
await pool.destroy()
const numberOfExitEvents = await exitPromise
expect(pool.started).toBe(false)
it('Shutdown test', async () => {
const exitPromise = waitWorkerEvents(pool, 'exit', min)
+ expect(pool.emitter.eventNames()).toStrictEqual([PoolEvents.busy])
let poolDestroy = 0
pool.emitter.on(PoolEvents.destroy, () => ++poolDestroy)
+ expect(pool.emitter.eventNames()).toStrictEqual([
+ PoolEvents.busy,
+ PoolEvents.destroy
+ ])
await pool.destroy()
const numberOfExitEvents = await exitPromise
expect(pool.started).toBe(false)
errorHandler: e => console.error(e)
}
)
+ expect(pool.emitter.eventNames()).toStrictEqual([])
let poolReady = 0
pool.emitter.on(PoolEvents.ready, () => ++poolReady)
await waitPoolEvents(pool, PoolEvents.ready, 1)
+ expect(pool.emitter.eventNames()).toStrictEqual([PoolEvents.ready])
expect(poolReady).toBe(1)
await pool.destroy()
})
it("Verify that 'busy' event is emitted", async () => {
const promises = new Set()
+ expect(pool.emitter.eventNames()).toStrictEqual([])
let poolBusy = 0
pool.emitter.on(PoolEvents.busy, () => ++poolBusy)
+ expect(pool.emitter.eventNames()).toStrictEqual([PoolEvents.busy])
for (let i = 0; i < numberOfThreads * 2; i++) {
promises.add(pool.execute())
}
it('Verify that error handling is working properly:sync', async () => {
const data = { f: 10 }
+ expect(errorPool.emitter.eventNames()).toStrictEqual([])
let taskError
errorPool.emitter.on(PoolEvents.taskError, e => {
taskError = e
})
+ expect(errorPool.emitter.eventNames()).toStrictEqual([PoolEvents.taskError])
let inError
try {
await errorPool.execute(data)
it('Verify that error handling is working properly:async', async () => {
const data = { f: 10 }
+ expect(asyncErrorPool.emitter.eventNames()).toStrictEqual([])
let taskError
asyncErrorPool.emitter.on(PoolEvents.taskError, e => {
taskError = e
})
+ expect(asyncErrorPool.emitter.eventNames()).toStrictEqual([
+ PoolEvents.taskError
+ ])
let inError
try {
await asyncErrorPool.execute(data)