1 const { expect
} = require('expect')
2 // const sinon = require('sinon')
4 getWorkerChoiceStrategy
5 } = require('../../../lib/pools/selection-strategies/selection-strategies-utils')
9 } = require('../../../lib/index')
11 RoundRobinWorkerChoiceStrategy
12 } = require('../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy')
14 LessUsedWorkerChoiceStrategy
15 } = require('../../../lib/pools/selection-strategies/less-used-worker-choice-strategy')
17 LessBusyWorkerChoiceStrategy
18 } = require('../../../lib/pools/selection-strategies/less-busy-worker-choice-strategy')
20 FairShareWorkerChoiceStrategy
21 } = require('../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy')
23 WeightedRoundRobinWorkerChoiceStrategy
24 } = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy')
26 describe('Selection strategies utils test suite', () => {
31 pool
= new FixedThreadPool(max
, './tests/worker-files/thread/testWorker.js')
42 it('Verify that getWorkerChoiceStrategy() default return ROUND_ROBIN strategy', () => {
43 const strategy
= getWorkerChoiceStrategy(pool
)
44 expect(strategy
).toBeInstanceOf(RoundRobinWorkerChoiceStrategy
)
47 it('Verify that getWorkerChoiceStrategy() can return ROUND_ROBIN strategy', () => {
48 const strategy
= getWorkerChoiceStrategy(
50 WorkerChoiceStrategies
.ROUND_ROBIN
52 expect(strategy
).toBeInstanceOf(RoundRobinWorkerChoiceStrategy
)
55 it('Verify that getWorkerChoiceStrategy() can return LESS_USED strategy', () => {
56 const strategy
= getWorkerChoiceStrategy(
58 WorkerChoiceStrategies
.LESS_USED
60 expect(strategy
).toBeInstanceOf(LessUsedWorkerChoiceStrategy
)
63 it('Verify that getWorkerChoiceStrategy() can return LESS_BUSY strategy', () => {
64 const strategy
= getWorkerChoiceStrategy(
66 WorkerChoiceStrategies
.LESS_BUSY
68 expect(strategy
).toBeInstanceOf(LessBusyWorkerChoiceStrategy
)
71 it('Verify that getWorkerChoiceStrategy() can return FAIR_SHARE strategy', () => {
72 const strategy
= getWorkerChoiceStrategy(
74 WorkerChoiceStrategies
.FAIR_SHARE
76 expect(strategy
).toBeInstanceOf(FairShareWorkerChoiceStrategy
)
79 it('Verify that getWorkerChoiceStrategy() can return WEIGHTED_ROUND_ROBIN strategy', () => {
80 const strategy
= getWorkerChoiceStrategy(
82 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
84 expect(strategy
).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy
)
87 it('Verify that getWorkerChoiceStrategy() throw error on unknown strategy', () => {
89 getWorkerChoiceStrategy(pool
, 'UNKNOWN_STRATEGY')
91 new Error("Worker choice strategy 'UNKNOWN_STRATEGY' not found")