const worker = this.createAndSetupWorker()
this.registerWorkerMessageListener<Data>(worker, message => {
const tasksInProgress = this.tasks.get(worker)
- if (message.kill) {
+ if (message.kill && !tasksInProgress) {
this.sendToWorker(worker, { kill: 1 })
void this.destroyWorker(worker)
}
max,
'./tests/worker/cluster/testWorker.js',
{
- errorHandler: e => console.error(e),
- onlineHandler: () => console.log('worker is online')
+ errorHandler: e => console.error(e)
}
)
pool.execute({ test: 'test' })
}
expect(pool.workers.length).toBeGreaterThan(min)
- await new Promise(resolve => setTimeout(resolve, 2000))
+ await new Promise(resolve => setTimeout(resolve, 3000))
expect(pool.workers.length).toBe(min)
})
it('Shutdown test', async () => {
})
})
pool.destroy()
- await new Promise(resolve => setTimeout(resolve, 1000))
+ await new Promise(resolve => setTimeout(resolve, 2000))
expect(closedWorkers).toBe(min)
})
const longRunningPool = new DynamicClusterPool(
min,
max,
- './tests/worker/thread/longRunningWorker.js'
+ './tests/worker/cluster/longRunningWorker.js'
)
expect(longRunningPool.workers.length).toBe(min)
for (let i = 0; i < max * 10; i++) {
longRunningPool.execute({ test: 'test' })
}
expect(longRunningPool.workers.length).toBe(max)
- await new Promise(resolve => setTimeout(resolve, 1000))
+ await new Promise(resolve => setTimeout(resolve, 3000))
// Here we expect the workers to be at the max size since that the task is still running
expect(longRunningPool.workers.length).toBe(max)
})
numberOfWorkers,
'./tests/worker/cluster/testWorker.js',
{
- errorHandler: e => console.error(e),
- onlineHandler: () => console.log('worker is online')
+ errorHandler: e => console.error(e)
}
)
const emptyPool = new FixedClusterPool(
1,
'./tests/worker/cluster/errorWorker.js',
{
- errorHandler: e => console.error(e),
- onlineHandler: () => console.log('worker is online')
+ errorHandler: e => console.error(e)
}
)
numberOfThreads,
'./tests/worker/thread/testWorker.js',
{
- errorHandler: e => console.error(e),
- onlineHandler: () => console.log('worker is online')
+ errorHandler: e => console.error(e)
}
)
const emptyPool = new FixedThreadPool(1, './tests/worker/thread/emptyWorker.js')