From: Jérôme Benoit Date: Mon, 10 Jul 2023 11:12:43 +0000 (+0200) Subject: refactor: prepare worker choice strategies code for worker readiness X-Git-Tag: v2.6.15~17 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9b1068374b1a52479b07e1e22b692289d5579237;p=poolifier.git refactor: prepare worker choice strategies code for worker readiness Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index cb5d4ce7..4bf7785d 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -953,18 +953,21 @@ export abstract class AbstractPool< worker.on('message', this.opts.messageHandler ?? EMPTY_FUNCTION) worker.on('error', this.opts.errorHandler ?? EMPTY_FUNCTION) worker.on('error', error => { + const workerNodeKey = this.getWorkerNodeKey(worker) + const workerInfo = this.getWorkerInfo(workerNodeKey) + workerInfo.ready = false if (this.emitter != null) { this.emitter.emit(PoolEvents.error, error) } if (this.opts.restartWorkerOnError === true && !this.starting) { - if (this.getWorkerInfo(this.getWorkerNodeKey(worker)).dynamic) { + if (workerInfo.dynamic) { this.createAndSetupDynamicWorker() } else { this.createAndSetupWorker() } } if (this.opts.enableTasksQueue === true) { - this.redistributeQueuedTasks(worker) + this.redistributeQueuedTasks(workerNodeKey) } }) worker.on('online', this.opts.onlineHandler ?? EMPTY_FUNCTION) @@ -980,8 +983,7 @@ export abstract class AbstractPool< return worker } - private redistributeQueuedTasks (worker: Worker): void { - const workerNodeKey = this.getWorkerNodeKey(worker) + private redistributeQueuedTasks (workerNodeKey: number): void { while (this.tasksQueueSize(workerNodeKey) > 0) { let targetWorkerNodeKey: number = workerNodeKey let minQueuedTasks = Infinity diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index a6589d09..c4f1e2c6 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -30,9 +30,9 @@ export abstract class AbstractWorkerChoiceStrategy< // private toggleFindLastFreeWorkerNodeKey: boolean = false /** - * Id of the next worker node. + * The next worker node key. */ - protected nextWorkerNodeId: number = 0 + protected nextWorkerNodeKey: number = 0 /** @inheritDoc */ public readonly strategyPolicy: StrategyPolicy = { @@ -128,7 +128,7 @@ export abstract class AbstractWorkerChoiceStrategy< this.setTaskStatisticsRequirements(this.opts) } - protected workerNodeReady (workerNodeKey: number): boolean { + protected isWorkerNodeReady (workerNodeKey: number): boolean { return this.pool.workerNodes[workerNodeKey].info.ready } diff --git a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts index 351f3d91..00c56dad 100644 --- a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts @@ -70,6 +70,17 @@ export class FairShareWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number { + this.fairShareNextWorkerNodeKey() + return this.nextWorkerNodeKey + } + + /** @inheritDoc */ + public remove (workerNodeKey: number): boolean { + this.workersVirtualTaskEndTimestamp.splice(workerNodeKey, 1) + return true + } + + private fairShareNextWorkerNodeKey (): void { let minWorkerVirtualTaskEndTimestamp = Infinity for (const [workerNodeKey] of this.pool.workerNodes.entries()) { if (this.workersVirtualTaskEndTimestamp[workerNodeKey] == null) { @@ -78,20 +89,13 @@ export class FairShareWorkerChoiceStrategy< const workerVirtualTaskEndTimestamp = this.workersVirtualTaskEndTimestamp[workerNodeKey] if ( - this.workerNodeReady(workerNodeKey) && + this.isWorkerNodeReady(workerNodeKey) && workerVirtualTaskEndTimestamp < minWorkerVirtualTaskEndTimestamp ) { minWorkerVirtualTaskEndTimestamp = workerVirtualTaskEndTimestamp - this.nextWorkerNodeId = workerNodeKey + this.nextWorkerNodeKey = workerNodeKey } } - return this.nextWorkerNodeId - } - - /** @inheritDoc */ - public remove (workerNodeKey: number): boolean { - this.workersVirtualTaskEndTimestamp.splice(workerNodeKey, 1) - return true } /** diff --git a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts index 40522c72..78960f10 100644 --- a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts @@ -54,7 +54,7 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy< /** @inheritDoc */ public reset (): boolean { - this.nextWorkerNodeId = 0 + this.nextWorkerNodeKey = 0 this.roundId = 0 return true } @@ -74,7 +74,7 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy< roundIndex++ ) { for ( - let workerNodeKey = this.nextWorkerNodeId; + let workerNodeKey = this.nextWorkerNodeKey; workerNodeKey < this.pool.workerNodes.length; workerNodeKey++ ) { @@ -88,25 +88,25 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy< } } this.roundId = roundId ?? 0 - this.nextWorkerNodeId = workerNodeId ?? 0 - const chosenWorkerNodeKey = this.nextWorkerNodeId - if (this.nextWorkerNodeId === this.pool.workerNodes.length - 1) { - this.nextWorkerNodeId = 0 + this.nextWorkerNodeKey = workerNodeId ?? 0 + const chosenWorkerNodeKey = this.nextWorkerNodeKey + if (this.nextWorkerNodeKey === this.pool.workerNodes.length - 1) { + this.nextWorkerNodeKey = 0 this.roundId = this.roundId === this.roundWeights.length - 1 ? 0 : this.roundId + 1 } else { - this.nextWorkerNodeId = this.nextWorkerNodeId + 1 + this.nextWorkerNodeKey = this.nextWorkerNodeKey + 1 } return chosenWorkerNodeKey } /** @inheritDoc */ public remove (workerNodeKey: number): boolean { - if (this.nextWorkerNodeId === workerNodeKey) { + if (this.nextWorkerNodeKey === workerNodeKey) { if (this.pool.workerNodes.length === 0) { - this.nextWorkerNodeId = 0 - } else if (this.nextWorkerNodeId > this.pool.workerNodes.length - 1) { - this.nextWorkerNodeId = this.pool.workerNodes.length - 1 + this.nextWorkerNodeKey = 0 + } else if (this.nextWorkerNodeKey > this.pool.workerNodes.length - 1) { + this.nextWorkerNodeKey = this.pool.workerNodes.length - 1 this.roundId = this.roundId === this.roundWeights.length - 1 ? 0 : this.roundId + 1 } diff --git a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts index b61bca1c..dabad682 100644 --- a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts @@ -61,24 +61,31 @@ export class LeastBusyWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number { + this.leastBusyNextWorkerNodeKey() + return this.nextWorkerNodeKey + } + + /** @inheritDoc */ + public remove (): boolean { + return true + } + + private leastBusyNextWorkerNodeKey (): void { let minTime = Infinity for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerTime = (workerNode.usage.runTime?.aggregate ?? 0) + (workerNode.usage.waitTime?.aggregate ?? 0) - if (this.workerNodeReady(workerNodeKey) && workerTime === 0) { - this.nextWorkerNodeId = workerNodeKey + if (this.isWorkerNodeReady(workerNodeKey) && workerTime === 0) { + this.nextWorkerNodeKey = workerNodeKey break - } else if (this.workerNodeReady(workerNodeKey) && workerTime < minTime) { + } else if ( + this.isWorkerNodeReady(workerNodeKey) && + workerTime < minTime + ) { minTime = workerTime - this.nextWorkerNodeId = workerNodeKey + this.nextWorkerNodeKey = workerNodeKey } } - return this.nextWorkerNodeId - } - - /** @inheritDoc */ - public remove (): boolean { - return true } } diff --git a/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts b/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts index 57e805e1..24c612e0 100644 --- a/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts @@ -57,26 +57,30 @@ export class LeastEluWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number { + this.leastEluNextWorkerNodeKey() + return this.nextWorkerNodeKey + } + + /** @inheritDoc */ + public remove (): boolean { + return true + } + + private leastEluNextWorkerNodeKey (): void { let minWorkerElu = Infinity for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerUsage = workerNode.usage const workerElu = workerUsage.elu?.active?.aggregate ?? 0 - if (this.workerNodeReady(workerNodeKey) && workerElu === 0) { - this.nextWorkerNodeId = workerNodeKey + if (this.isWorkerNodeReady(workerNodeKey) && workerElu === 0) { + this.nextWorkerNodeKey = workerNodeKey break } else if ( - this.workerNodeReady(workerNodeKey) && + this.isWorkerNodeReady(workerNodeKey) && workerElu < minWorkerElu ) { minWorkerElu = workerElu - this.nextWorkerNodeId = workerNodeKey + this.nextWorkerNodeKey = workerNodeKey } } - return this.nextWorkerNodeId - } - - /** @inheritDoc */ - public remove (): boolean { - return true } } diff --git a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts index 8c138470..910d10a3 100644 --- a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts @@ -42,6 +42,16 @@ export class LeastUsedWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number { + this.leastUsedNextWorkerNodeKey() + return this.nextWorkerNodeKey + } + + /** @inheritDoc */ + public remove (): boolean { + return true + } + + private leastUsedNextWorkerNodeKey (): void { let minNumberOfTasks = Infinity for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerTaskStatistics = workerNode.usage.tasks @@ -49,22 +59,16 @@ export class LeastUsedWorkerChoiceStrategy< workerTaskStatistics.executed + workerTaskStatistics.executing + workerTaskStatistics.queued - if (this.workerNodeReady(workerNodeKey) && workerTasks === 0) { - this.nextWorkerNodeId = workerNodeKey + if (this.isWorkerNodeReady(workerNodeKey) && workerTasks === 0) { + this.nextWorkerNodeKey = workerNodeKey break } else if ( - this.workerNodeReady(workerNodeKey) && + this.isWorkerNodeReady(workerNodeKey) && workerTasks < minNumberOfTasks ) { minNumberOfTasks = workerTasks - this.nextWorkerNodeId = workerNodeKey + this.nextWorkerNodeKey = workerNodeKey } } - return this.nextWorkerNodeId - } - - /** @inheritDoc */ - public remove (): boolean { - return true } } diff --git a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts index 83586093..fdf5ac84 100644 --- a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts @@ -38,7 +38,7 @@ export class RoundRobinWorkerChoiceStrategy< /** @inheritDoc */ public reset (): boolean { - this.nextWorkerNodeId = 0 + this.nextWorkerNodeKey = 0 return true } @@ -49,23 +49,27 @@ export class RoundRobinWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number { - const chosenWorkerNodeKey = this.nextWorkerNodeId - this.nextWorkerNodeId = - this.nextWorkerNodeId === this.pool.workerNodes.length - 1 - ? 0 - : this.nextWorkerNodeId + 1 + const chosenWorkerNodeKey = this.nextWorkerNodeKey + this.roundRobinNextWorkerNodeKey() return chosenWorkerNodeKey } /** @inheritDoc */ public remove (workerNodeKey: number): boolean { - if (this.nextWorkerNodeId === workerNodeKey) { + if (this.nextWorkerNodeKey === workerNodeKey) { if (this.pool.workerNodes.length === 0) { - this.nextWorkerNodeId = 0 - } else if (this.nextWorkerNodeId > this.pool.workerNodes.length - 1) { - this.nextWorkerNodeId = this.pool.workerNodes.length - 1 + this.nextWorkerNodeKey = 0 + } else if (this.nextWorkerNodeKey > this.pool.workerNodes.length - 1) { + this.nextWorkerNodeKey = this.pool.workerNodes.length - 1 } } return true } + + private roundRobinNextWorkerNodeKey (): void { + this.nextWorkerNodeKey = + this.nextWorkerNodeKey === this.pool.workerNodes.length - 1 + ? 0 + : this.nextWorkerNodeKey + 1 + } } diff --git a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts index 28051330..ed38aa14 100644 --- a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts @@ -64,7 +64,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy< /** @inheritDoc */ public reset (): boolean { - this.nextWorkerNodeId = 0 + this.nextWorkerNodeKey = 0 this.workerVirtualTaskRunTime = 0 return true } @@ -76,34 +76,38 @@ export class WeightedRoundRobinWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number { - const chosenWorkerNodeKey = this.nextWorkerNodeId - const workerVirtualTaskRunTime = this.workerVirtualTaskRunTime - const workerWeight = - this.opts.weights?.[chosenWorkerNodeKey] ?? this.defaultWorkerWeight - if (workerVirtualTaskRunTime < workerWeight) { - this.workerVirtualTaskRunTime = - workerVirtualTaskRunTime + - this.getWorkerTaskRunTime(chosenWorkerNodeKey) - } else { - this.nextWorkerNodeId = - this.nextWorkerNodeId === this.pool.workerNodes.length - 1 - ? 0 - : this.nextWorkerNodeId + 1 - this.workerVirtualTaskRunTime = 0 - } + const chosenWorkerNodeKey = this.nextWorkerNodeKey + this.weightedRoundRobinNextWorkerNodeKey() return chosenWorkerNodeKey } /** @inheritDoc */ public remove (workerNodeKey: number): boolean { - if (this.nextWorkerNodeId === workerNodeKey) { + if (this.nextWorkerNodeKey === workerNodeKey) { if (this.pool.workerNodes.length === 0) { - this.nextWorkerNodeId = 0 - } else if (this.nextWorkerNodeId > this.pool.workerNodes.length - 1) { - this.nextWorkerNodeId = this.pool.workerNodes.length - 1 + this.nextWorkerNodeKey = 0 + } else if (this.nextWorkerNodeKey > this.pool.workerNodes.length - 1) { + this.nextWorkerNodeKey = this.pool.workerNodes.length - 1 } this.workerVirtualTaskRunTime = 0 } return true } + + private weightedRoundRobinNextWorkerNodeKey (): void { + const workerVirtualTaskRunTime = this.workerVirtualTaskRunTime + const workerWeight = + this.opts.weights?.[this.nextWorkerNodeKey] ?? this.defaultWorkerWeight + if (workerVirtualTaskRunTime < workerWeight) { + this.workerVirtualTaskRunTime = + workerVirtualTaskRunTime + + this.getWorkerTaskRunTime(this.nextWorkerNodeKey) + } else { + this.nextWorkerNodeKey = + this.nextWorkerNodeKey === this.pool.workerNodes.length - 1 + ? 0 + : this.nextWorkerNodeKey + 1 + this.workerVirtualTaskRunTime = 0 + } + } } diff --git a/tests/pools/cluster/dynamic.test.js b/tests/pools/cluster/dynamic.test.js index bd405a77..a6d0b594 100644 --- a/tests/pools/cluster/dynamic.test.js +++ b/tests/pools/cluster/dynamic.test.js @@ -103,7 +103,7 @@ describe('Dynamic cluster pool test suite', () => { expect( longRunningPool.workerChoiceStrategyContext.workerChoiceStrategies.get( longRunningPool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBeLessThan(longRunningPool.workerNodes.length) // We need to clean up the resources after our test await longRunningPool.destroy() diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index 2e1a49b6..c3a01da6 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -79,7 +79,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) } else if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) { expect( @@ -98,7 +98,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -236,7 +236,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( WorkerChoiceStrategies.ROUND_ROBIN - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) // We need to clean up the resources after our test await pool.destroy() @@ -284,7 +284,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( WorkerChoiceStrategies.ROUND_ROBIN - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) // We need to clean up the resources after our test await pool.destroy() @@ -326,13 +326,13 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBeDefined() pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) await pool.destroy() pool = new DynamicThreadPool( @@ -344,13 +344,13 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBeDefined() pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) // We need to clean up the resources after our test await pool.destroy() @@ -1555,7 +1555,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1571,7 +1571,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1592,7 +1592,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1608,7 +1608,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1760,7 +1760,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1830,7 +1830,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1860,7 +1860,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1881,7 +1881,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1911,7 +1911,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBeDefined() expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1927,7 +1927,7 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( pool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBe(0) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( diff --git a/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.js b/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.js index 7cdd327b..e9de670a 100644 --- a/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.js +++ b/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.js @@ -32,7 +32,7 @@ describe('Weighted round robin strategy worker choice strategy test suite', () = ) const resetResult = strategy.reset() expect(resetResult).toBe(true) - expect(strategy.nextWorkerNodeId).toBe(0) + expect(strategy.nextWorkerNodeKey).toBe(0) expect(strategy.workerVirtualTaskRunTime).toBe(0) }) }) diff --git a/tests/pools/thread/dynamic.test.js b/tests/pools/thread/dynamic.test.js index 56847302..4f3dfb6d 100644 --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.js @@ -103,7 +103,7 @@ describe('Dynamic thread pool test suite', () => { expect( longRunningPool.workerChoiceStrategyContext.workerChoiceStrategies.get( longRunningPool.workerChoiceStrategyContext.workerChoiceStrategy - ).nextWorkerNodeId + ).nextWorkerNodeKey ).toBeLessThan(longRunningPool.workerNodes.length) // We need to clean up the resources after our test await longRunningPool.destroy()