X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fselection-strategies%2Fworker-choice-strategy-context.test.js;h=62a2bd44f558e6307e8510e7d48e4942088d82e9;hb=a1c82d5d3cc4e6c932a065018b20ed716e9c3051;hp=79bcf2a165eabfcad1c224ff83824336a0a95fec;hpb=cdace0e5b9082804893de9501372490ee1064090;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 79bcf2a1..62a2bd44 100644 --- a/tests/pools/selection-strategies/worker-choice-strategy-context.test.js +++ b/tests/pools/selection-strategies/worker-choice-strategy-context.test.js @@ -12,17 +12,23 @@ const { RoundRobinWorkerChoiceStrategy } = require('../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy') const { - LessUsedWorkerChoiceStrategy -} = require('../../../lib/pools/selection-strategies/less-used-worker-choice-strategy') + LeastUsedWorkerChoiceStrategy +} = require('../../../lib/pools/selection-strategies/least-used-worker-choice-strategy') const { - LessBusyWorkerChoiceStrategy -} = require('../../../lib/pools/selection-strategies/less-busy-worker-choice-strategy') + LeastBusyWorkerChoiceStrategy +} = require('../../../lib/pools/selection-strategies/least-busy-worker-choice-strategy') +const { + LeastEluWorkerChoiceStrategy +} = require('../../../lib/pools/selection-strategies/least-elu-worker-choice-strategy') const { FairShareWorkerChoiceStrategy } = require('../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy') const { WeightedRoundRobinWorkerChoiceStrategy } = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy') +const { + InterleavedWeightedRoundRobinWorkerChoiceStrategy +} = require('../../../lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy') describe('Worker choice strategy context test suite', () => { const min = 1 @@ -85,6 +91,41 @@ describe('Worker choice strategy context test suite', () => { expect(chosenWorkerKey).toBe(0) }) + it('Verify that execute() throws error if null or undefined is returned', () => { + const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( + fixedPool + ) + const WorkerChoiceStrategyUndefinedStub = sinon.createStubInstance( + RoundRobinWorkerChoiceStrategy, + { + choose: sinon.stub().returns(undefined) + } + ) + const WorkerChoiceStrategyNullStub = sinon.createStubInstance( + RoundRobinWorkerChoiceStrategy, + { + choose: sinon.stub().returns(null) + } + ) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe( + WorkerChoiceStrategies.ROUND_ROBIN + ) + workerChoiceStrategyContext.workerChoiceStrategies.set( + workerChoiceStrategyContext.workerChoiceStrategy, + WorkerChoiceStrategyUndefinedStub + ) + expect(() => workerChoiceStrategyContext.execute()).toThrowError( + new Error('Worker node key chosen is null or undefined') + ) + workerChoiceStrategyContext.workerChoiceStrategies.set( + workerChoiceStrategyContext.workerChoiceStrategy, + WorkerChoiceStrategyNullStub + ) + expect(() => workerChoiceStrategyContext.execute()).toThrowError( + new Error('Worker node key chosen is null or undefined') + ) + }) + it('Verify that execute() return the worker chosen by the strategy with dynamic pool', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( dynamicPool @@ -116,11 +157,6 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool ) - expect( - workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).isDynamicPool - ).toBe(false) expect( workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy @@ -145,11 +181,6 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( dynamicPool ) - expect( - workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).isDynamicPool - ).toBe(true) expect( workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy @@ -169,85 +200,97 @@ describe('Worker choice strategy context test suite', () => { ) }) - it('Verify that setWorkerChoiceStrategy() works with LESS_USED and fixed pool', () => { - const workerChoiceStrategy = WorkerChoiceStrategies.LESS_USED + it('Verify that setWorkerChoiceStrategy() works with LEAST_USED and fixed pool', () => { + const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_USED const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool ) - expect( - workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).isDynamicPool - ).toBe(false) workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy) expect( workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy ) - ).toBeInstanceOf(LessUsedWorkerChoiceStrategy) + ).toBeInstanceOf(LeastUsedWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe( workerChoiceStrategy ) }) - it('Verify that setWorkerChoiceStrategy() works with LESS_USED and dynamic pool', () => { - const workerChoiceStrategy = WorkerChoiceStrategies.LESS_USED + it('Verify that setWorkerChoiceStrategy() works with LEAST_USED and dynamic pool', () => { + const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_USED const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( dynamicPool ) - expect( - workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).isDynamicPool - ).toBe(true) workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy) expect( workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy ) - ).toBeInstanceOf(LessUsedWorkerChoiceStrategy) + ).toBeInstanceOf(LeastUsedWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe( workerChoiceStrategy ) }) - it('Verify that setWorkerChoiceStrategy() works with LESS_BUSY and fixed pool', () => { - const workerChoiceStrategy = WorkerChoiceStrategies.LESS_BUSY + it('Verify that setWorkerChoiceStrategy() works with LEAST_BUSY and fixed pool', () => { + const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_BUSY const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool ) + workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy) expect( workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).isDynamicPool - ).toBe(false) + ) + ).toBeInstanceOf(LeastBusyWorkerChoiceStrategy) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe( + workerChoiceStrategy + ) + }) + + it('Verify that setWorkerChoiceStrategy() works with LEAST_BUSY and dynamic pool', () => { + const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_BUSY + const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( + dynamicPool + ) workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy) expect( workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy ) - ).toBeInstanceOf(LessBusyWorkerChoiceStrategy) + ).toBeInstanceOf(LeastBusyWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe( workerChoiceStrategy ) }) - it('Verify that setWorkerChoiceStrategy() works with LESS_BUSY and dynamic pool', () => { - const workerChoiceStrategy = WorkerChoiceStrategies.LESS_BUSY + it('Verify that setWorkerChoiceStrategy() works with LEAST_ELU and fixed pool', () => { + const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_ELU const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( - dynamicPool + fixedPool ) + workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy) expect( workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).isDynamicPool - ).toBe(true) + ) + ).toBeInstanceOf(LeastEluWorkerChoiceStrategy) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe( + workerChoiceStrategy + ) + }) + + it('Verify that setWorkerChoiceStrategy() works with LEAST_ELU and dynamic pool', () => { + const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_ELU + const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( + dynamicPool + ) workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy) expect( workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy ) - ).toBeInstanceOf(LessBusyWorkerChoiceStrategy) + ).toBeInstanceOf(LeastEluWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe( workerChoiceStrategy ) @@ -258,11 +301,6 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool ) - expect( - workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).isDynamicPool - ).toBe(false) workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy) expect( workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -279,11 +317,6 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( dynamicPool ) - expect( - workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).isDynamicPool - ).toBe(true) workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy) expect( workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -300,11 +333,6 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool ) - expect( - workerChoiceStrategyContext.workerChoiceStrategies.get( - workerChoiceStrategy - ).isDynamicPool - ).toBe(false) workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy) expect( workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -321,23 +349,52 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( dynamicPool ) + workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy) expect( workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy - ).isDynamicPool - ).toBe(true) + ) + ).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe( + workerChoiceStrategy + ) + }) + + it('Verify that setWorkerChoiceStrategy() works with INTERLEAVED_WEIGHTED_ROUND_ROBIN and fixed pool', () => { + const workerChoiceStrategy = + WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN + const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( + fixedPool + ) workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy) expect( workerChoiceStrategyContext.workerChoiceStrategies.get( workerChoiceStrategy ) - ).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy) + ).toBeInstanceOf(InterleavedWeightedRoundRobinWorkerChoiceStrategy) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe( + workerChoiceStrategy + ) + }) + + it('Verify that setWorkerChoiceStrategy() works with INTERLEAVED_WEIGHTED_ROUND_ROBIN and dynamic pool', () => { + const workerChoiceStrategy = + WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN + const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( + dynamicPool + ) + workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + workerChoiceStrategy + ) + ).toBeInstanceOf(InterleavedWeightedRoundRobinWorkerChoiceStrategy) expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe( workerChoiceStrategy ) }) - it('Verify that worker choice strategy options enable median run time pool statistics', () => { + it('Verify that worker choice strategy options enable median runtime pool statistics', () => { const wwrWorkerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN let workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool, @@ -346,12 +403,12 @@ describe('Worker choice strategy context test suite', () => { medRunTime: true } ) - expect(workerChoiceStrategyContext.getRequiredStatistics().avgRunTime).toBe( - false - ) - expect(workerChoiceStrategyContext.getRequiredStatistics().medRunTime).toBe( - true - ) + expect( + workerChoiceStrategyContext.getTaskStatisticsRequirements().avgRunTime + ).toBe(false) + expect( + workerChoiceStrategyContext.getTaskStatisticsRequirements().medRunTime + ).toBe(true) workerChoiceStrategyContext = new WorkerChoiceStrategyContext( dynamicPool, wwrWorkerChoiceStrategy, @@ -359,12 +416,12 @@ describe('Worker choice strategy context test suite', () => { medRunTime: true } ) - expect(workerChoiceStrategyContext.getRequiredStatistics().avgRunTime).toBe( - false - ) - expect(workerChoiceStrategyContext.getRequiredStatistics().medRunTime).toBe( - true - ) + expect( + workerChoiceStrategyContext.getTaskStatisticsRequirements().avgRunTime + ).toBe(false) + expect( + workerChoiceStrategyContext.getTaskStatisticsRequirements().medRunTime + ).toBe(true) const fsWorkerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool, @@ -373,12 +430,12 @@ describe('Worker choice strategy context test suite', () => { medRunTime: true } ) - expect(workerChoiceStrategyContext.getRequiredStatistics().avgRunTime).toBe( - false - ) - expect(workerChoiceStrategyContext.getRequiredStatistics().medRunTime).toBe( - true - ) + expect( + workerChoiceStrategyContext.getTaskStatisticsRequirements().avgRunTime + ).toBe(false) + expect( + workerChoiceStrategyContext.getTaskStatisticsRequirements().medRunTime + ).toBe(true) workerChoiceStrategyContext = new WorkerChoiceStrategyContext( dynamicPool, fsWorkerChoiceStrategy, @@ -386,11 +443,11 @@ describe('Worker choice strategy context test suite', () => { medRunTime: true } ) - expect(workerChoiceStrategyContext.getRequiredStatistics().avgRunTime).toBe( - false - ) - expect(workerChoiceStrategyContext.getRequiredStatistics().medRunTime).toBe( - true - ) + expect( + workerChoiceStrategyContext.getTaskStatisticsRequirements().avgRunTime + ).toBe(false) + expect( + workerChoiceStrategyContext.getTaskStatisticsRequirements().medRunTime + ).toBe(true) }) })