| 1 | const { expect } = require('expect') |
| 2 | const sinon = require('sinon') |
| 3 | const { FixedThreadPool } = require('../../../lib') |
| 4 | const { |
| 5 | WeightedRoundRobinWorkerChoiceStrategy |
| 6 | } = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy') |
| 7 | const TestUtils = require('../../test-utils') |
| 8 | |
| 9 | describe('Weighted round robin strategy worker choice strategy test suite', () => { |
| 10 | // const min = 1 |
| 11 | const max = 3 |
| 12 | let pool |
| 13 | |
| 14 | before(() => { |
| 15 | pool = new FixedThreadPool(max, './tests/worker-files/thread/testWorker.js') |
| 16 | }) |
| 17 | |
| 18 | afterEach(() => { |
| 19 | sinon.restore() |
| 20 | }) |
| 21 | |
| 22 | after(async () => { |
| 23 | await pool.destroy() |
| 24 | }) |
| 25 | |
| 26 | it('Verify that reset() resets internals', () => { |
| 27 | const strategy = new WeightedRoundRobinWorkerChoiceStrategy(pool) |
| 28 | strategy.currentWorkerId = TestUtils.generateRandomInteger( |
| 29 | Number.MAX_SAFE_INTEGER, |
| 30 | 1 |
| 31 | ) |
| 32 | strategy.workerVirtualTaskRunTime = TestUtils.generateRandomInteger( |
| 33 | Number.MAX_SAFE_INTEGER, |
| 34 | 1 |
| 35 | ) |
| 36 | const resetResult = strategy.reset() |
| 37 | expect(resetResult).toBe(true) |
| 38 | expect(strategy.nextWorkerNodeId).toBe(0) |
| 39 | expect(strategy.workerVirtualTaskRunTime).toBe(0) |
| 40 | }) |
| 41 | }) |