it('Verify that new workers are created when required, max size is not exceeded and that after a while new workers will die', async () => {
const promises = []
- let fullPool = 0
- pool.emitter.on('FullPool', () => fullPool++)
+ let poolBusy = 0
+ pool.emitter.on('busy', () => poolBusy++)
for (let i = 0; i < max * 2; i++) {
promises.push(pool.execute({ test: 'test' }))
}
expect(pool.workers.length).toBe(max)
- expect(fullPool > 1).toBeTruthy()
+ expect(poolBusy).toEqual(max + 1)
const res = await TestUtils.waitExits(pool, max - min)
expect(res).toBe(max - min)
})
expect(closedThreads).toBe(min)
})
- it('Validations test', () => {
- expect(() => {
- const pool1 = new DynamicThreadPool()
- }).toThrowError(
+ it('Validation of inputs test', () => {
+ expect(() => new DynamicThreadPool(min)).toThrowError(
new Error('Please specify a file with a worker implementation')
)
})
// We need to clean up the resources after our test
await longRunningPool.destroy()
})
+
+ it('Verify that a pool with zero worker can be instantiated', async () => {
+ const pool = new DynamicThreadPool(
+ 0,
+ max,
+ './tests/worker-files/thread/testWorker.js'
+ )
+ expect(pool).toBeInstanceOf(DynamicThreadPool)
+ // We need to clean up the resources after our test
+ await pool.destroy()
+ })
})