1 const expect
= require('expect')
3 WorkerChoiceStrategies
,
6 } = require('../../lib/index')
7 const TestUtils
= require('../test-utils')
9 describe('Selection strategies test suite', () => {
10 it('Verify that WorkerChoiceStrategies enumeration provides string values', () => {
11 expect(WorkerChoiceStrategies
.ROUND_ROBIN
).toBe('ROUND_ROBIN')
12 expect(WorkerChoiceStrategies
.LESS_RECENTLY_USED
).toBe('LESS_RECENTLY_USED')
15 it('Verify LESS_RECENTLY_USED is taken', async () => {
17 const pool
= new FixedThreadPool(
19 './tests/worker-files/thread/testWorker.js',
20 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_RECENTLY_USED
}
23 expect(pool
.opts
.workerChoiceStrategy
).toBe(
24 WorkerChoiceStrategies
.LESS_RECENTLY_USED
27 // TODO: Create a better test to cover `LessRecentlyUsedWorkerChoiceStrategy#choose`
29 for (let i
= 0; i
< max
* 2; i
++) {
30 promises
.push(pool
.execute({ test
: 'test' }))
32 await Promise
.all(promises
)
34 // We need to clean up the resources after our test
38 it('Verify unknown strategies throw error', () => {
43 new DynamicThreadPool(
46 './tests/worker-files/thread/testWorker.js',
49 workerChoiceStrategy
: 'UNKNOWN_STRATEGY'
53 new Error("Worker choice strategy 'UNKNOWN_STRATEGY' not found")