1 const { expect
} = require('expect')
2 const sinon
= require('sinon')
3 const { FixedThreadPool
} = require('../../../lib/index')
5 WeightedRoundRobinWorkerChoiceStrategy
6 } = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy')
7 const TestUtils
= require('../../test-utils')
9 describe('Weighted round robin strategy worker choice strategy test suite', () => {
15 pool
= new FixedThreadPool(max
, './tests/worker-files/thread/testWorker.js')
26 it('Verify that reset() resets internals', () => {
27 const strategy
= new WeightedRoundRobinWorkerChoiceStrategy(pool
)
28 strategy
.previousWorkerIndex
= TestUtils
.generateRandomInteger(
29 Number
.MAX_SAFE_INTEGER
31 strategy
.currentWorkerIndex
= TestUtils
.generateRandomInteger(
32 Number
.MAX_SAFE_INTEGER
34 const workersTaskRunTimeClearStub
= sinon
35 .stub(strategy
.workersTaskRunTime
, 'clear')
37 const initWorkersTaskRunTimeStub
= sinon
38 .stub(strategy
, 'initWorkersTaskRunTime')
40 const resetResult
= strategy
.reset()
41 expect(resetResult
).toBe(true)
42 expect(strategy
.previousWorkerIndex
).toBe(0)
43 expect(strategy
.currentWorkerIndex
).toBe(0)
44 expect(workersTaskRunTimeClearStub
.calledOnce
).toBe(true)
45 expect(initWorkersTaskRunTimeStub
.calledOnce
).toBe(true)