Commit | Line | Data |
---|---|---|
0220f124 JB |
1 | const { expect } = require('expect') |
2 | const sinon = require('sinon') | |
3 | const { FixedThreadPool } = require('../../../lib/index') | |
4 | const { | |
5 | WeightedRoundRobinWorkerChoiceStrategy | |
6 | } = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy') | |
7 | ||
8 | describe('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 | ||
6cdd998c | 25 | it('Verify that reset() resets internals', () => { |
0220f124 JB |
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 | }) |