X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fselection-strategies%2Fworker-choice-strategy-context.test.js;h=1f4b51cbf4d13956fd9ff5ef6c4550c3630e10f6;hb=7c24d88bad050638ec120e599f4752d589f87690;hp=3ce8b9fe040218f9b8e3be0b7a184b87737af0a6;hpb=b0afa8e5b4aa17b920ac920a5e517993afccc2a3;p=poolifier.git 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 3ce8b9fe..1f4b51cb 100644 --- a/tests/pools/selection-strategies/worker-choice-strategy-context.test.js +++ b/tests/pools/selection-strategies/worker-choice-strategy-context.test.js @@ -12,8 +12,11 @@ const { RoundRobinWorkerChoiceStrategy } = require('../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy') const { - LessRecentlyUsedWorkerChoiceStrategy -} = require('../../../lib/pools/selection-strategies/less-recently-used-worker-choice-strategy') + LessUsedWorkerChoiceStrategy +} = require('../../../lib/pools/selection-strategies/less-used-worker-choice-strategy') +const { + LessBusyWorkerChoiceStrategy +} = require('../../../lib/pools/selection-strategies/less-busy-worker-choice-strategy') const { FairShareWorkerChoiceStrategy } = require('../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy') @@ -57,15 +60,15 @@ describe('Worker choice strategy context test suite', () => { const WorkerChoiceStrategyStub = sinon.createStubInstance( RoundRobinWorkerChoiceStrategy, { - choose: sinon.stub().returns('worker') + choose: sinon.stub().returns(0) } ) workerChoiceStrategyContext.workerChoiceStrategy = WorkerChoiceStrategyStub - const chosenWorker = workerChoiceStrategyContext.execute() + const chosenWorkerKey = workerChoiceStrategyContext.execute() expect( - workerChoiceStrategyContext.getWorkerChoiceStrategy().choose.calledOnce + workerChoiceStrategyContext.workerChoiceStrategy.choose.calledOnce ).toBe(true) - expect(chosenWorker).toBe('worker') + expect(chosenWorkerKey).toBe(0) }) it('Verify that execute() return the worker chosen by the strategy with dynamic pool', () => { @@ -75,15 +78,15 @@ describe('Worker choice strategy context test suite', () => { const WorkerChoiceStrategyStub = sinon.createStubInstance( RoundRobinWorkerChoiceStrategy, { - choose: sinon.stub().returns('worker') + choose: sinon.stub().returns(0) } ) workerChoiceStrategyContext.workerChoiceStrategy = WorkerChoiceStrategyStub - const chosenWorker = workerChoiceStrategyContext.execute() + const chosenWorkerKey = workerChoiceStrategyContext.execute() expect( - workerChoiceStrategyContext.getWorkerChoiceStrategy().choose.calledOnce + workerChoiceStrategyContext.workerChoiceStrategy.choose.calledOnce ).toBe(true) - expect(chosenWorker).toBe('worker') + expect(chosenWorkerKey).toBe(0) }) it('Verify that setWorkerChoiceStrategy() works with ROUND_ROBIN and fixed pool', () => { @@ -93,9 +96,9 @@ describe('Worker choice strategy context test suite', () => { workerChoiceStrategyContext.setWorkerChoiceStrategy( WorkerChoiceStrategies.ROUND_ROBIN ) - expect( - workerChoiceStrategyContext.getWorkerChoiceStrategy() - ).toBeInstanceOf(RoundRobinWorkerChoiceStrategy) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( + RoundRobinWorkerChoiceStrategy + ) }) it('Verify that setWorkerChoiceStrategy() works with ROUND_ROBIN and dynamic pool', () => { @@ -105,39 +108,66 @@ describe('Worker choice strategy context test suite', () => { workerChoiceStrategyContext.setWorkerChoiceStrategy( WorkerChoiceStrategies.ROUND_ROBIN ) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( + DynamicPoolWorkerChoiceStrategy + ) expect( - workerChoiceStrategyContext.getWorkerChoiceStrategy() - ).toBeInstanceOf(DynamicPoolWorkerChoiceStrategy) - expect( - workerChoiceStrategyContext.getWorkerChoiceStrategy().workerChoiceStrategy + workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy ).toBeInstanceOf(RoundRobinWorkerChoiceStrategy) }) - it('Verify that setWorkerChoiceStrategy() works with LESS_RECENTLY_USED and fixed pool', () => { + it('Verify that setWorkerChoiceStrategy() works with LESS_USED and fixed pool', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool ) workerChoiceStrategyContext.setWorkerChoiceStrategy( - WorkerChoiceStrategies.LESS_RECENTLY_USED + WorkerChoiceStrategies.LESS_USED + ) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( + LessUsedWorkerChoiceStrategy ) - expect( - workerChoiceStrategyContext.getWorkerChoiceStrategy() - ).toBeInstanceOf(LessRecentlyUsedWorkerChoiceStrategy) }) - it('Verify that setWorkerChoiceStrategy() works with LESS_RECENTLY_USED and dynamic pool', () => { + it('Verify that setWorkerChoiceStrategy() works with LESS_USED and dynamic pool', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( dynamicPool ) workerChoiceStrategyContext.setWorkerChoiceStrategy( - WorkerChoiceStrategies.LESS_RECENTLY_USED + WorkerChoiceStrategies.LESS_USED + ) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( + DynamicPoolWorkerChoiceStrategy ) expect( - workerChoiceStrategyContext.getWorkerChoiceStrategy() - ).toBeInstanceOf(DynamicPoolWorkerChoiceStrategy) + workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy + ).toBeInstanceOf(LessUsedWorkerChoiceStrategy) + }) + + it('Verify that setWorkerChoiceStrategy() works with LESS_BUSY and fixed pool', () => { + const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( + fixedPool + ) + workerChoiceStrategyContext.setWorkerChoiceStrategy( + WorkerChoiceStrategies.LESS_BUSY + ) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( + LessBusyWorkerChoiceStrategy + ) + }) + + it('Verify that setWorkerChoiceStrategy() works with LESS_BUSY and dynamic pool', () => { + const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( + dynamicPool + ) + workerChoiceStrategyContext.setWorkerChoiceStrategy( + WorkerChoiceStrategies.LESS_BUSY + ) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( + DynamicPoolWorkerChoiceStrategy + ) expect( - workerChoiceStrategyContext.getWorkerChoiceStrategy().workerChoiceStrategy - ).toBeInstanceOf(LessRecentlyUsedWorkerChoiceStrategy) + workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy + ).toBeInstanceOf(LessBusyWorkerChoiceStrategy) }) it('Verify that setWorkerChoiceStrategy() works with FAIR_SHARE and fixed pool', () => { @@ -147,9 +177,9 @@ describe('Worker choice strategy context test suite', () => { workerChoiceStrategyContext.setWorkerChoiceStrategy( WorkerChoiceStrategies.FAIR_SHARE ) - expect( - workerChoiceStrategyContext.getWorkerChoiceStrategy() - ).toBeInstanceOf(FairShareWorkerChoiceStrategy) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( + FairShareWorkerChoiceStrategy + ) }) it('Verify that setWorkerChoiceStrategy() works with FAIR_SHARE and dynamic pool', () => { @@ -159,11 +189,11 @@ describe('Worker choice strategy context test suite', () => { workerChoiceStrategyContext.setWorkerChoiceStrategy( WorkerChoiceStrategies.FAIR_SHARE ) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( + DynamicPoolWorkerChoiceStrategy + ) expect( - workerChoiceStrategyContext.getWorkerChoiceStrategy() - ).toBeInstanceOf(DynamicPoolWorkerChoiceStrategy) - expect( - workerChoiceStrategyContext.getWorkerChoiceStrategy().workerChoiceStrategy + workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy ).toBeInstanceOf(FairShareWorkerChoiceStrategy) }) @@ -174,9 +204,9 @@ describe('Worker choice strategy context test suite', () => { workerChoiceStrategyContext.setWorkerChoiceStrategy( WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN ) - expect( - workerChoiceStrategyContext.getWorkerChoiceStrategy() - ).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( + WeightedRoundRobinWorkerChoiceStrategy + ) }) it('Verify that setWorkerChoiceStrategy() works with WEIGHTED_ROUND_ROBIN and dynamic pool', () => { @@ -186,11 +216,11 @@ describe('Worker choice strategy context test suite', () => { workerChoiceStrategyContext.setWorkerChoiceStrategy( WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN ) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( + DynamicPoolWorkerChoiceStrategy + ) expect( - workerChoiceStrategyContext.getWorkerChoiceStrategy() - ).toBeInstanceOf(DynamicPoolWorkerChoiceStrategy) - expect( - workerChoiceStrategyContext.getWorkerChoiceStrategy().workerChoiceStrategy + workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy ).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy) }) })