| 1 | import { expect } from 'expect' |
| 2 | import { FixedThreadPool } from '../../../lib/index.js' |
| 3 | import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.js' |
| 4 | import { generateRandomInteger } from '../../test-utils.js' |
| 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 = generateRandomInteger(Number.MAX_SAFE_INTEGER, 1) |
| 25 | strategy.workerVirtualTaskRunTime = generateRandomInteger( |
| 26 | Number.MAX_SAFE_INTEGER, |
| 27 | 1 |
| 28 | ) |
| 29 | expect(strategy.reset()).toBe(true) |
| 30 | expect(strategy.nextWorkerNodeKey).toBe(0) |
| 31 | expect(strategy.previousWorkerNodeKey).toBe(0) |
| 32 | expect(strategy.workerNodeVirtualTaskRunTime).toBe(0) |
| 33 | }) |
| 34 | }) |