test: switch thread worker to ESM
[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(
14 max,
15 './tests/worker-files/thread/testWorker.mjs'
16 )
17 })
18
19 afterEach(() => {
20 restore()
21 })
22
23 after(async () => {
24 await pool.destroy()
25 })
26
27 it('Verify that reset() resets internals', () => {
28 const strategy = new WeightedRoundRobinWorkerChoiceStrategy(pool)
29 strategy.currentWorkerId = generateRandomInteger(Number.MAX_SAFE_INTEGER, 1)
30 strategy.workerVirtualTaskRunTime = generateRandomInteger(
31 Number.MAX_SAFE_INTEGER,
32 1
33 )
34 expect(strategy.reset()).toBe(true)
35 expect(strategy.nextWorkerNodeKey).toBe(0)
36 expect(strategy.previousWorkerNodeKey).toBe(0)
37 expect(strategy.workerNodeVirtualTaskRunTime).toBe(0)
38 })
39 })