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