const { FixedClusterPool } = require('../../../lib/index')
const TestUtils = require('../../test-utils')
const numberOfWorkers = 10
-const maxTasks = 500
const pool = new FixedClusterPool(
numberOfWorkers,
'./tests/worker-files/cluster/testWorker.js',
errorHandler: e => console.error(e)
}
)
-
const asyncErrorPool = new FixedClusterPool(
1,
'./tests/worker-files/cluster/asyncErrorWorker.js',
)
const asyncPool = new FixedClusterPool(
1,
- './tests/worker-files/cluster/asyncWorker.js',
- {
- maxTasks: maxTasks
- }
+ './tests/worker-files/cluster/asyncWorker.js'
)
-describe('Fixed cluster pool test suite ', () => {
+describe('Fixed cluster pool test suite', () => {
after('Destroy all pools', async () => {
// We need to clean up the resources after our test
await echoPool.destroy()
expect(usedTime).toBeGreaterThanOrEqual(2000)
})
- it('Verify that maxTasks is set properly', async () => {
- const worker = asyncPool.chooseWorker()
- expect(worker.getMaxListeners()).toBe(maxTasks)
- })
-
it('Shutdown test', async () => {
const exitPromise = TestUtils.waitExits(pool, numberOfWorkers)
await pool.destroy()
// We need to clean up the resources after our test
await pool1.destroy()
})
+
+ it('Verify that a pool with zero worker fails', async () => {
+ expect(
+ () =>
+ new FixedClusterPool(0, './tests/worker-files/cluster/testWorker.js')
+ ).toThrowError(new Error('Cannot instantiate a fixed pool with no worker'))
+ })
})