c659b31e7bcc2dec1db31a0a7554b1b82cb6c549
[poolifier.git] / tests / pools / selection-strategies / weighted-round-robin-worker-choice-strategy.test.mjs
1 import { expect } from 'expect'
2 import { restore } from 'sinon'
3 import { FixedThreadPool } from '../../../lib/index.js'
4 import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.js'
5 import { generateRandomInteger } from '../../test-utils.js'
6
7 describe('Weighted round robin strategy worker choice strategy test suite', () => {
8 // const min = 1
9 const max = 3
10 let pool
11
12 before(() => {
13 pool = new FixedThreadPool(max, './tests/worker-files/thread/testWorker.js')
14 })
15
16 afterEach(() => {
17 restore()
18 })
19
20 after(async () => {
21 await pool.destroy()
22 })
23
24 it('Verify that reset() resets internals', () => {
25 const strategy = new WeightedRoundRobinWorkerChoiceStrategy(pool)
26 strategy.currentWorkerId = generateRandomInteger(Number.MAX_SAFE_INTEGER, 1)
27 strategy.workerVirtualTaskRunTime = generateRandomInteger(
28 Number.MAX_SAFE_INTEGER,
29 1
30 )
31 expect(strategy.reset()).toBe(true)
32 expect(strategy.nextWorkerNodeKey).toBe(0)
33 expect(strategy.previousWorkerNodeKey).toBe(0)
34 expect(strategy.workerNodeVirtualTaskRunTime).toBe(0)
35 })
36 })