perf: use a single map to store pool workers and their related data
[poolifier.git] / tests / pools / selection-strategies / weighted-round-robin-worker-choice-strategy.test.js
CommitLineData
0220f124
JB
1const { expect } = require('expect')
2const sinon = require('sinon')
3const { FixedThreadPool } = require('../../../lib/index')
4const {
5 WeightedRoundRobinWorkerChoiceStrategy
6} = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy')
f931db5c 7const TestUtils = require('../../test-utils')
0220f124
JB
8
9describe('Weighted round robin strategy worker choice strategy test suite', () => {
10 // const min = 1
11 const max = 3
12 let pool
13
14 before(() => {
15 pool = new FixedThreadPool(max, './tests/worker-files/thread/testWorker.js')
16 })
17
18 afterEach(() => {
19 sinon.restore()
20 })
21
22 after(async () => {
23 await pool.destroy()
24 })
25
6cdd998c 26 it('Verify that reset() resets internals', () => {
0220f124 27 const strategy = new WeightedRoundRobinWorkerChoiceStrategy(pool)
ffcbbad8 28 strategy.currentWorkerId = TestUtils.generateRandomInteger()
0220f124
JB
29 const workersTaskRunTimeClearStub = sinon
30 .stub(strategy.workersTaskRunTime, 'clear')
31 .returns()
32 const initWorkersTaskRunTimeStub = sinon
33 .stub(strategy, 'initWorkersTaskRunTime')
34 .returns()
35 const resetResult = strategy.reset()
36 expect(resetResult).toBe(true)
ffcbbad8 37 expect(strategy.currentWorkerId).toBe(0)
0220f124
JB
38 expect(workersTaskRunTimeClearStub.calledOnce).toBe(true)
39 expect(initWorkersTaskRunTimeStub.calledOnce).toBe(true)
40 })
41})