Commit | Line | Data |
---|---|---|
c7ed5d3b | 1 | import { randomInt } from 'node:crypto' |
a074ffee | 2 | import { expect } from 'expect' |
d35e5717 JB |
3 | import { FixedThreadPool } from '../../../lib/index.cjs' |
4 | import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.cjs' | |
0220f124 JB |
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(() => { | |
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) |
a1fef95a JB |
24 | strategy.nextWorkerNodeKey = randomInt(1, 281474976710655) |
25 | strategy.previousWorkerNodeKey = randomInt(1, 281474976710655) | |
26 | strategy.workerNodeVirtualTaskRunTime = randomInt(1, 281474976710655) | |
27 | expect(strategy.nextWorkerNodeKey).toBeGreaterThan(0) | |
28 | expect(strategy.previousWorkerNodeKey).toBeGreaterThan(0) | |
29 | expect(strategy.workerNodeVirtualTaskRunTime).toBeGreaterThan(0) | |
516dcb0d | 30 | expect(strategy.reset()).toBe(true) |
9b106837 | 31 | expect(strategy.nextWorkerNodeKey).toBe(0) |
54f4e726 | 32 | expect(strategy.previousWorkerNodeKey).toBe(0) |
f3a91bac | 33 | expect(strategy.workerNodeVirtualTaskRunTime).toBe(0) |
0220f124 JB |
34 | }) |
35 | }) |