1 const expect
= require('expect')
3 WorkerChoiceStrategies
,
6 } = require('../../lib/index')
8 describe('Selection strategies test suite', () => {
9 it('Verify that WorkerChoiceStrategies enumeration provides string values', () => {
10 expect(WorkerChoiceStrategies
.ROUND_ROBIN
).toBe('ROUND_ROBIN')
11 expect(WorkerChoiceStrategies
.LESS_RECENTLY_USED
).toBe('LESS_RECENTLY_USED')
14 it('Verify LESS_RECENTLY_USED strategy is taken', async () => {
16 const pool
= new FixedThreadPool(
18 './tests/worker-files/thread/testWorker.js',
19 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_RECENTLY_USED
}
22 expect(pool
.opts
.workerChoiceStrategy
).toBe(
23 WorkerChoiceStrategies
.LESS_RECENTLY_USED
26 // TODO: Create a better test to cover `LessRecentlyUsedWorkerChoiceStrategy#choose`
28 for (let i
= 0; i
< max
* 2; i
++) {
29 promises
.push(pool
.execute({ test
: 'test' }))
31 await Promise
.all(promises
)
33 // We need to clean up the resources after our test
37 it('Verify unknown strategies throw error', () => {
42 new DynamicThreadPool(
45 './tests/worker-files/thread/testWorker.js',
48 workerChoiceStrategy
: 'UNKNOWN_STRATEGY'
52 new Error("Worker choice strategy 'UNKNOWN_STRATEGY' not found")