const expect = require('expect')
-const { FixedClusterPool, FixedThreadPool } = require('../../../lib/index')
+const {
+ FixedClusterPool,
+ FixedThreadPool,
+ WorkerChoiceStrategies
+} = require('../../../lib/index')
const expectedError = new Error('Worker could not be found in tasks map')
const numberOfWorkers = 1
})
it('Verify that filePath is checked', () => {
+ const expectedError = new Error(
+ 'Please specify a file with a worker implementation'
+ )
expect(() => new FixedThreadPool(numberOfWorkers)).toThrowError(
- new Error('Please specify a file with a worker implementation')
+ expectedError
)
expect(() => new FixedThreadPool(numberOfWorkers, '')).toThrowError(
- new Error('Please specify a file with a worker implementation')
+ expectedError
)
})
numberOfWorkers,
'./tests/worker-files/thread/testWorker.js'
)
- expect(pool.opts.enableEvents).toEqual(true)
+ expect(pool.opts.enableEvents).toBe(true)
expect(pool.emitter).toBeDefined()
+ expect(pool.opts.workerChoiceStrategy).toBe(
+ WorkerChoiceStrategies.ROUND_ROBIN
+ )
pool.destroy()
pool = new FixedThreadPool(
numberOfWorkers,
'./tests/worker-files/thread/testWorker.js',
{
+ workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED,
enableEvents: false
}
)
- expect(pool.opts.enableEvents).toEqual(false)
+ expect(pool.opts.enableEvents).toBe(false)
expect(pool.emitter).toBeUndefined()
+ expect(pool.opts.workerChoiceStrategy).toBe(
+ WorkerChoiceStrategies.LESS_RECENTLY_USED
+ )
pool.destroy()
})
for (let i = 0; i < numberOfWorkers * 2; i++) {
promises.push(pool.execute({ test: 'test' }))
}
- expect(poolBusy).toEqual(numberOfWorkers)
+ expect(poolBusy).toBe(numberOfWorkers)
pool.destroy()
})
})