From: Jérôme Benoit Date: Wed, 5 Apr 2023 21:12:28 +0000 (+0200) Subject: feat: cache in a map worker choice strategy to allow conditionnal reuse X-Git-Tag: v2.4.2~10 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=95c83464bb1fab234d1c41204f98defcd01c789f;p=poolifier.git feat: cache in a map worker choice strategy to allow conditionnal reuse Signed-off-by: Jérôme Benoit --- diff --git a/CHANGELOG.md b/CHANGELOG.md index a2cc015d..30d1e724 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add `full` event to dynamic pool. +- Keep worker choice strategy usage in memory for reuse. ## [2.4.1] - 2023-04-05 diff --git a/src/pools/selection-strategies/worker-choice-strategy-context.ts b/src/pools/selection-strategies/worker-choice-strategy-context.ts index 644adfea..90c98c60 100644 --- a/src/pools/selection-strategies/worker-choice-strategy-context.ts +++ b/src/pools/selection-strategies/worker-choice-strategy-context.ts @@ -24,7 +24,10 @@ export class WorkerChoiceStrategyContext< Data = unknown, Response = unknown > { - private workerChoiceStrategy: IWorkerChoiceStrategy + private readonly workerChoiceStrategies = new Map< + WorkerChoiceStrategy, + IWorkerChoiceStrategy + >() /** * Worker choice strategy context constructor. @@ -39,10 +42,7 @@ export class WorkerChoiceStrategyContext< private workerChoiceStrategyType: WorkerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN ) { this.execute.bind(this) - this.workerChoiceStrategy = this.getWorkerChoiceStrategy( - pool, - this.workerChoiceStrategyType - ) + this.registerWorkerChoiceStrategy(pool, workerChoiceStrategyType) } /** @@ -51,7 +51,11 @@ export class WorkerChoiceStrategyContext< * @returns The required statistics. */ public getRequiredStatistics (): RequiredStatistics { - return this.workerChoiceStrategy.requiredStatistics + return ( + this.workerChoiceStrategies.get( + this.workerChoiceStrategyType + ) as IWorkerChoiceStrategy + ).requiredStatistics } /** @@ -64,13 +68,10 @@ export class WorkerChoiceStrategyContext< workerChoiceStrategy: WorkerChoiceStrategy ): void { if (this.workerChoiceStrategyType === workerChoiceStrategy) { - this.workerChoiceStrategy?.reset() + this.workerChoiceStrategies.get(workerChoiceStrategy)?.reset() } else { this.workerChoiceStrategyType = workerChoiceStrategy - this.workerChoiceStrategy = this.getWorkerChoiceStrategy( - pool, - this.workerChoiceStrategyType - ) + this.registerWorkerChoiceStrategy(pool, workerChoiceStrategy) } } @@ -80,14 +81,17 @@ export class WorkerChoiceStrategyContext< * @returns The key of the chosen one. */ public execute (): number { + const workerChoiceStrategy = this.workerChoiceStrategies.get( + this.workerChoiceStrategyType + ) as IWorkerChoiceStrategy if ( - this.workerChoiceStrategy.isDynamicPool && - !this.workerChoiceStrategy.pool.full && - this.workerChoiceStrategy.pool.findFreeWorkerKey() === -1 + workerChoiceStrategy.isDynamicPool && + !workerChoiceStrategy.pool.full && + workerChoiceStrategy.pool.findFreeWorkerKey() === -1 ) { return this.createWorkerCallback() } - return this.workerChoiceStrategy.choose() + return workerChoiceStrategy.choose() } /** @@ -97,7 +101,23 @@ export class WorkerChoiceStrategyContext< * @returns `true` if the removal is successful, `false` otherwise. */ public remove (workerKey: number): boolean { - return this.workerChoiceStrategy.remove(workerKey) + return ( + this.workerChoiceStrategies.get( + this.workerChoiceStrategyType + ) as IWorkerChoiceStrategy + ).remove(workerKey) + } + + private registerWorkerChoiceStrategy ( + pool: IPoolInternal, + workerChoiceStrategy: WorkerChoiceStrategy + ): void { + if (!this.workerChoiceStrategies.has(workerChoiceStrategy)) { + this.workerChoiceStrategies.set( + workerChoiceStrategy, + this.getWorkerChoiceStrategy(pool, workerChoiceStrategy) + ) + } } /** diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index 71a2819b..254f02de 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -43,7 +43,9 @@ describe('Selection strategies test suite', () => { WorkerChoiceStrategies.ROUND_ROBIN ) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.ROUND_ROBIN + ).nextWorkerId ).toBe(0) // We need to clean up the resources after our test await pool.destroy() @@ -158,11 +160,15 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN } ) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.ROUND_ROBIN + )?.nextWorkerId ).toBeUndefined() pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.ROUND_ROBIN + ).nextWorkerId ).toBe(0) await pool.destroy() pool = new DynamicThreadPool( @@ -172,11 +178,15 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN } ) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.ROUND_ROBIN + )?.nextWorkerId ).toBeUndefined() pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.ROUND_ROBIN + ).nextWorkerId ).toBe(0) // We need to clean up the resources after our test await pool.destroy() @@ -367,16 +377,18 @@ describe('Selection strategies test suite', () => { expect(pool.opts.workerChoiceStrategy).toBe( WorkerChoiceStrategies.FAIR_SHARE ) - for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) { + for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.FAIR_SHARE) + .workerLastVirtualTaskTimestamp.keys()) { expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get( - workerKey - ).start + pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.FAIR_SHARE) + .workerLastVirtualTaskTimestamp.get(workerKey).start ).toBe(0) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get( - workerKey - ).end + pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.FAIR_SHARE) + .workerLastVirtualTaskTimestamp.get(workerKey).end ).toBe(0) } // We need to clean up the resources after our test @@ -438,8 +450,9 @@ describe('Selection strategies test suite', () => { } await Promise.all(promises) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy - .workerLastVirtualTaskTimestamp.size + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.FAIR_SHARE + ).workerLastVirtualTaskTimestamp.size ).toBe(pool.workers.length) // We need to clean up the resources after our test await pool.destroy() @@ -461,8 +474,9 @@ describe('Selection strategies test suite', () => { await Promise.all(promises) // if (process.platform !== 'win32') { // expect( - // pool.workerChoiceStrategyContext.workerChoiceStrategy - // .workerLastVirtualTaskTimestamp.size + // pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + // WorkerChoiceStrategies.FAIR_SHARE + // ).workerLastVirtualTaskTimestamp.size // ).toBe(pool.workers.length) // } // We need to clean up the resources after our test @@ -475,20 +489,23 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js' ) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy - .workerLastVirtualTaskTimestamp + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.FAIR_SHARE + )?.workerLastVirtualTaskTimestamp ).toBeUndefined() pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE) - for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) { + for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.FAIR_SHARE) + .workerLastVirtualTaskTimestamp.keys()) { expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get( - workerKey - ).start + pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.FAIR_SHARE) + .workerLastVirtualTaskTimestamp.get(workerKey).start ).toBe(0) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get( - workerKey - ).end + pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.FAIR_SHARE) + .workerLastVirtualTaskTimestamp.get(workerKey).end ).toBe(0) } await pool.destroy() @@ -498,20 +515,23 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js' ) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy - .workerLastVirtualTaskTimestamp + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.FAIR_SHARE + )?.workerLastVirtualTaskTimestamp ).toBeUndefined() pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE) - for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) { + for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.FAIR_SHARE) + .workerLastVirtualTaskTimestamp.keys()) { expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get( - workerKey - ).start + pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.FAIR_SHARE) + .workerLastVirtualTaskTimestamp.get(workerKey).start ).toBe(0) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get( - workerKey - ).end + pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.FAIR_SHARE) + .workerLastVirtualTaskTimestamp.get(workerKey).end ).toBe(0) } // We need to clean up the resources after our test @@ -528,21 +548,27 @@ describe('Selection strategies test suite', () => { WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN ) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ).currentWorkerId ).toBe(0) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ).defaultWorkerWeight ).toBeGreaterThan(0) - for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.keys()) { + for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN) + .workersTaskRunTime.keys()) { expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get( - workerKey - ).weight + pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN) + .workersTaskRunTime.get(workerKey).weight ).toBeGreaterThan(0) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get( - workerKey - ).runTime + pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN) + .workersTaskRunTime.get(workerKey).runTime ).toBe(0) } // We need to clean up the resources after our test @@ -604,8 +630,9 @@ describe('Selection strategies test suite', () => { } await Promise.all(promises) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime - .size + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ).workersTaskRunTime.size ).toBe(pool.workers.length) // We need to clean up the resources after our test await pool.destroy() @@ -621,16 +648,18 @@ describe('Selection strategies test suite', () => { // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose` const promises = [] const maxMultiplier = - pool.workerChoiceStrategyContext.workerChoiceStrategy - .defaultWorkerWeight * 2 + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ).defaultWorkerWeight * 2 for (let i = 0; i < max * maxMultiplier; i++) { promises.push(pool.execute()) } await Promise.all(promises) if (process.platform !== 'win32') { expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime - .size + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ).workersTaskRunTime.size ).toBe(pool.workers.length) } // We need to clean up the resources after our test @@ -643,26 +672,38 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js' ) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + )?.currentWorkerId ).toBeUndefined() expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + )?.defaultWorkerWeight ).toBeUndefined() expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + )?.workersTaskRunTime ).toBeUndefined() pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ).currentWorkerId ).toBe(0) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ).defaultWorkerWeight ).toBeGreaterThan(0) - for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.keys()) { + for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN) + .workersTaskRunTime.keys()) { expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get( - workerKey - ).runTime + pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN) + .workersTaskRunTime.get(workerKey).runTime ).toBe(0) } await pool.destroy() @@ -672,26 +713,38 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js' ) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + )?.currentWorkerId ).toBeUndefined() expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + )?.defaultWorkerWeight ).toBeUndefined() expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + )?.workersTaskRunTime ).toBeUndefined() pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ).currentWorkerId ).toBe(0) expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ).defaultWorkerWeight ).toBeGreaterThan(0) - for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.keys()) { + for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN) + .workersTaskRunTime.keys()) { expect( - pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get( - workerKey - ).runTime + pool.workerChoiceStrategyContext.workerChoiceStrategies + .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN) + .workersTaskRunTime.get(workerKey).runTime ).toBe(0) } // We need to clean up the resources after our test diff --git a/tests/pools/selection-strategies/worker-choice-strategy-context.test.js b/tests/pools/selection-strategies/worker-choice-strategy-context.test.js index a93104d2..0f02c363 100644 --- a/tests/pools/selection-strategies/worker-choice-strategy-context.test.js +++ b/tests/pools/selection-strategies/worker-choice-strategy-context.test.js @@ -60,10 +60,18 @@ describe('Worker choice strategy context test suite', () => { choose: sinon.stub().returns(0) } ) - workerChoiceStrategyContext.workerChoiceStrategy = WorkerChoiceStrategyStub + expect(workerChoiceStrategyContext.workerChoiceStrategyType).toBe( + WorkerChoiceStrategies.ROUND_ROBIN + ) + workerChoiceStrategyContext.workerChoiceStrategies.set( + workerChoiceStrategyContext.workerChoiceStrategyType, + WorkerChoiceStrategyStub + ) const chosenWorkerKey = workerChoiceStrategyContext.execute() expect( - workerChoiceStrategyContext.workerChoiceStrategy.choose.calledOnce + workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategyContext.workerChoiceStrategyType + ).choose.calledOnce ).toBe(true) expect(chosenWorkerKey).toBe(0) }) @@ -78,10 +86,18 @@ describe('Worker choice strategy context test suite', () => { choose: sinon.stub().returns(0) } ) - workerChoiceStrategyContext.workerChoiceStrategy = WorkerChoiceStrategyStub + expect(workerChoiceStrategyContext.workerChoiceStrategyType).toBe( + WorkerChoiceStrategies.ROUND_ROBIN + ) + workerChoiceStrategyContext.workerChoiceStrategies.set( + workerChoiceStrategyContext.workerChoiceStrategyType, + WorkerChoiceStrategyStub + ) const chosenWorkerKey = workerChoiceStrategyContext.execute() expect( - workerChoiceStrategyContext.workerChoiceStrategy.choose.calledOnce + workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategyContext.workerChoiceStrategyType + ).choose.calledOnce ).toBe(true) expect(chosenWorkerKey).toBe(0) }) @@ -90,9 +106,11 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - RoundRobinWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.ROUND_ROBIN + ) + ).toBeInstanceOf(RoundRobinWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategyType).toBe( WorkerChoiceStrategies.ROUND_ROBIN ) @@ -100,9 +118,11 @@ describe('Worker choice strategy context test suite', () => { fixedPool, WorkerChoiceStrategies.ROUND_ROBIN ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - RoundRobinWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.ROUND_ROBIN + ) + ).toBeInstanceOf(RoundRobinWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategyType).toBe( WorkerChoiceStrategies.ROUND_ROBIN ) @@ -112,9 +132,11 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( dynamicPool ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - RoundRobinWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.ROUND_ROBIN + ) + ).toBeInstanceOf(RoundRobinWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategyType).toBe( WorkerChoiceStrategies.ROUND_ROBIN ) @@ -122,9 +144,11 @@ describe('Worker choice strategy context test suite', () => { dynamicPool, WorkerChoiceStrategies.ROUND_ROBIN ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - RoundRobinWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.ROUND_ROBIN + ) + ).toBeInstanceOf(RoundRobinWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategyType).toBe( WorkerChoiceStrategies.ROUND_ROBIN ) @@ -138,9 +162,11 @@ describe('Worker choice strategy context test suite', () => { fixedPool, WorkerChoiceStrategies.LESS_USED ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - LessUsedWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.LESS_USED + ) + ).toBeInstanceOf(LessUsedWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategyType).toBe( WorkerChoiceStrategies.LESS_USED ) @@ -154,9 +180,11 @@ describe('Worker choice strategy context test suite', () => { dynamicPool, WorkerChoiceStrategies.LESS_USED ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - LessUsedWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.LESS_USED + ) + ).toBeInstanceOf(LessUsedWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategyType).toBe( WorkerChoiceStrategies.LESS_USED ) @@ -170,9 +198,11 @@ describe('Worker choice strategy context test suite', () => { fixedPool, WorkerChoiceStrategies.LESS_BUSY ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - LessBusyWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.LESS_BUSY + ) + ).toBeInstanceOf(LessBusyWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategyType).toBe( WorkerChoiceStrategies.LESS_BUSY ) @@ -186,9 +216,11 @@ describe('Worker choice strategy context test suite', () => { dynamicPool, WorkerChoiceStrategies.LESS_BUSY ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - LessBusyWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.LESS_BUSY + ) + ).toBeInstanceOf(LessBusyWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategyType).toBe( WorkerChoiceStrategies.LESS_BUSY ) @@ -202,9 +234,11 @@ describe('Worker choice strategy context test suite', () => { fixedPool, WorkerChoiceStrategies.FAIR_SHARE ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - FairShareWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.FAIR_SHARE + ) + ).toBeInstanceOf(FairShareWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategyType).toBe( WorkerChoiceStrategies.FAIR_SHARE ) @@ -218,9 +252,11 @@ describe('Worker choice strategy context test suite', () => { dynamicPool, WorkerChoiceStrategies.FAIR_SHARE ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - FairShareWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.FAIR_SHARE + ) + ).toBeInstanceOf(FairShareWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategyType).toBe( WorkerChoiceStrategies.FAIR_SHARE ) @@ -234,9 +270,11 @@ describe('Worker choice strategy context test suite', () => { fixedPool, WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - WeightedRoundRobinWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ) + ).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategyType).toBe( WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN ) @@ -250,9 +288,11 @@ describe('Worker choice strategy context test suite', () => { dynamicPool, WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - WeightedRoundRobinWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ) + ).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategyType).toBe( WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN )