refactor: remove home made random integer generator
[poolifier.git] / tests / pools / selection-strategies / weighted-round-robin-worker-choice-strategy.test.mjs
CommitLineData
c7ed5d3b 1import { randomInt } from 'node:crypto'
a074ffee 2import { expect } from 'expect'
d35e5717
JB
3import { FixedThreadPool } from '../../../lib/index.cjs'
4import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.cjs'
0220f124
JB
5
6describe('Weighted round robin strategy worker choice strategy test suite', () => {
7 // const min = 1
8 const max = 3
9 let pool
10
11 before(() => {
b2fd3f4a
JB
12 pool = new FixedThreadPool(
13 max,
14 './tests/worker-files/thread/testWorker.mjs'
15 )
0220f124
JB
16 })
17
0220f124
JB
18 after(async () => {
19 await pool.destroy()
20 })
21
6cdd998c 22 it('Verify that reset() resets internals', () => {
0220f124 23 const strategy = new WeightedRoundRobinWorkerChoiceStrategy(pool)
c7ed5d3b
JB
24 strategy.currentWorkerId = randomInt(281474976710655)
25 strategy.workerVirtualTaskRunTime = randomInt(281474976710655)
516dcb0d 26 expect(strategy.reset()).toBe(true)
9b106837 27 expect(strategy.nextWorkerNodeKey).toBe(0)
54f4e726 28 expect(strategy.previousWorkerNodeKey).toBe(0)
f3a91bac 29 expect(strategy.workerNodeVirtualTaskRunTime).toBe(0)
0220f124
JB
30 })
31})