const expect = require('expect')
const { FixedClusterPool } = require('../../../lib/index')
-const numWorkers = 10
+const numberOfWorkers = 10
const maxTasks = 500
const pool = new FixedClusterPool(
- numWorkers,
- './tests/worker/cluster/testWorker.js',
+ numberOfWorkers,
+ './tests/worker-files/cluster/testWorker.js',
{
errorHandler: e => console.error(e),
onlineHandler: () => console.log('worker is online')
)
const emptyPool = new FixedClusterPool(
1,
- './tests/worker/cluster/emptyWorker.js'
+ './tests/worker-files/cluster/emptyWorker.js'
+)
+const echoPool = new FixedClusterPool(
+ 1,
+ './tests/worker-files/cluster/echoWorker.js'
)
-const echoPool = new FixedClusterPool(1, './tests/worker/cluster/echoWorker.js')
const errorPool = new FixedClusterPool(
1,
- './tests/worker/cluster/errorWorker.js',
+ './tests/worker-files/cluster/errorWorker.js',
{
errorHandler: e => console.error(e),
onlineHandler: () => console.log('worker is online')
const asyncErrorPool = new FixedClusterPool(
1,
- './tests/worker/cluster/asyncErrorWorker.js',
+ './tests/worker-files/cluster/asyncErrorWorker.js',
{
onlineHandler: () => console.log('worker is online')
}
)
const asyncPool = new FixedClusterPool(
1,
- './tests/worker/cluster/asyncWorker.js',
+ './tests/worker-files/cluster/asyncWorker.js',
{
maxTasks: maxTasks
}
describe('Fixed cluster pool test suite ', () => {
it('Choose worker round robin test', async () => {
const results = new Set()
- for (let i = 0; i < numWorkers; i++) {
+ for (let i = 0; i < numberOfWorkers; i++) {
results.add(pool.chooseWorker().id)
}
- expect(results.size).toBe(numWorkers)
+ expect(results.size).toBe(numberOfWorkers)
})
it('Verify that the function is executed in a worker cluster', async () => {
closedWorkers++
})
})
- pool.destroy()
+ await pool.destroy()
await new Promise(resolve => setTimeout(resolve, 200))
- expect(closedWorkers).toBe(numWorkers)
+ expect(closedWorkers).toBe(numberOfWorkers)
})
it('Validations test', () => {
it('Should work even without opts in input', async () => {
const pool1 = new FixedClusterPool(
1,
- './tests/worker/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.js'
)
const res = await pool1.execute({ test: 'test' })
expect(res).toBeFalsy()