Add tests for WRR worker choice strategy
[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')
7
8describe('Weighted round robin strategy worker choice strategy test suite', () => {
9 // const min = 1
10 const max = 3
11 let pool
12
13 before(() => {
14 pool = new FixedThreadPool(max, './tests/worker-files/thread/testWorker.js')
15 })
16
17 afterEach(() => {
18 sinon.restore()
19 })
20
21 after(async () => {
22 await pool.destroy()
23 })
24
25 it.only('Verify that reset() resets internals', () => {
26 const strategy = new WeightedRoundRobinWorkerChoiceStrategy(pool)
27 const workersTaskRunTimeClearStub = sinon
28 .stub(strategy.workersTaskRunTime, 'clear')
29 .returns()
30 const initWorkersTaskRunTimeStub = sinon
31 .stub(strategy, 'initWorkersTaskRunTime')
32 .returns()
33 const resetResult = strategy.reset()
34 expect(resetResult).toBe(true)
35 expect(strategy.previousWorkerIndex).toBe(0)
36 expect(strategy.currentWorkerIndex).toBe(0)
37 expect(strategy.defaultWorkerWeight).toBeGreaterThan(0)
38 expect(workersTaskRunTimeClearStub.calledOnce).toBe(true)
39 expect(initWorkersTaskRunTimeStub.calledOnce).toBe(true)
40 })
41})