X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fselection-strategies%2Fworker-choice-strategy-context.test.js;h=a8f187eee6098fab5bb6c8ede3ec5cff434da3d3;hb=027063571693f211b35c8851566a063201adb9af;hp=0f02c363c0b2e3a90a5234faa2f4be4669b5959c;hpb=95c83464bb1fab234d1c41204f98defcd01c789f;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 0f02c363..a8f187ee 100644 --- a/tests/pools/selection-strategies/worker-choice-strategy-context.test.js +++ b/tests/pools/selection-strategies/worker-choice-strategy-context.test.js @@ -50,6 +50,15 @@ describe('Worker choice strategy context test suite', () => { await dynamicPool.destroy() }) + it('Verify that constructor() initializes the context with all the available worker choice strategies', () => { + const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( + fixedPool + ) + expect(workerChoiceStrategyContext.workerChoiceStrategies.size).toBe( + Object.keys(WorkerChoiceStrategies).length + ) + }) + it('Verify that execute() return the worker chosen by the strategy with fixed pool', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool @@ -106,6 +115,11 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.ROUND_ROBIN + ).isDynamicPool + ).toBe(false) expect( workerChoiceStrategyContext.workerChoiceStrategies.get( WorkerChoiceStrategies.ROUND_ROBIN @@ -115,7 +129,6 @@ describe('Worker choice strategy context test suite', () => { WorkerChoiceStrategies.ROUND_ROBIN ) workerChoiceStrategyContext.setWorkerChoiceStrategy( - fixedPool, WorkerChoiceStrategies.ROUND_ROBIN ) expect( @@ -132,6 +145,11 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( dynamicPool ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.ROUND_ROBIN + ).isDynamicPool + ).toBe(true) expect( workerChoiceStrategyContext.workerChoiceStrategies.get( WorkerChoiceStrategies.ROUND_ROBIN @@ -141,7 +159,6 @@ describe('Worker choice strategy context test suite', () => { WorkerChoiceStrategies.ROUND_ROBIN ) workerChoiceStrategyContext.setWorkerChoiceStrategy( - dynamicPool, WorkerChoiceStrategies.ROUND_ROBIN ) expect( @@ -158,8 +175,12 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.LESS_USED + ).isDynamicPool + ).toBe(false) workerChoiceStrategyContext.setWorkerChoiceStrategy( - fixedPool, WorkerChoiceStrategies.LESS_USED ) expect( @@ -176,8 +197,12 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( dynamicPool ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.LESS_USED + ).isDynamicPool + ).toBe(true) workerChoiceStrategyContext.setWorkerChoiceStrategy( - dynamicPool, WorkerChoiceStrategies.LESS_USED ) expect( @@ -194,8 +219,12 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.LESS_BUSY + ).isDynamicPool + ).toBe(false) workerChoiceStrategyContext.setWorkerChoiceStrategy( - fixedPool, WorkerChoiceStrategies.LESS_BUSY ) expect( @@ -212,8 +241,12 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( dynamicPool ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.LESS_BUSY + ).isDynamicPool + ).toBe(true) workerChoiceStrategyContext.setWorkerChoiceStrategy( - dynamicPool, WorkerChoiceStrategies.LESS_BUSY ) expect( @@ -230,8 +263,12 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.FAIR_SHARE + ).isDynamicPool + ).toBe(false) workerChoiceStrategyContext.setWorkerChoiceStrategy( - fixedPool, WorkerChoiceStrategies.FAIR_SHARE ) expect( @@ -248,8 +285,12 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( dynamicPool ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.FAIR_SHARE + ).isDynamicPool + ).toBe(true) workerChoiceStrategyContext.setWorkerChoiceStrategy( - dynamicPool, WorkerChoiceStrategies.FAIR_SHARE ) expect( @@ -266,8 +307,12 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ).isDynamicPool + ).toBe(false) workerChoiceStrategyContext.setWorkerChoiceStrategy( - fixedPool, WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN ) expect( @@ -284,8 +329,12 @@ describe('Worker choice strategy context test suite', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( dynamicPool ) + expect( + workerChoiceStrategyContext.workerChoiceStrategies.get( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ).isDynamicPool + ).toBe(true) workerChoiceStrategyContext.setWorkerChoiceStrategy( - dynamicPool, WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN ) expect( @@ -297,82 +346,4 @@ describe('Worker choice strategy context test suite', () => { WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN ) }) - - it('Verify that getWorkerChoiceStrategy() default return ROUND_ROBIN strategy', () => { - const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( - fixedPool - ) - const strategy = - workerChoiceStrategyContext.getWorkerChoiceStrategy(fixedPool) - expect(strategy).toBeInstanceOf(RoundRobinWorkerChoiceStrategy) - }) - - it('Verify that getWorkerChoiceStrategy() can return ROUND_ROBIN strategy', () => { - const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( - fixedPool - ) - const strategy = workerChoiceStrategyContext.getWorkerChoiceStrategy( - fixedPool, - WorkerChoiceStrategies.ROUND_ROBIN - ) - expect(strategy).toBeInstanceOf(RoundRobinWorkerChoiceStrategy) - }) - - it('Verify that getWorkerChoiceStrategy() can return LESS_USED strategy', () => { - const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( - fixedPool - ) - const strategy = workerChoiceStrategyContext.getWorkerChoiceStrategy( - fixedPool, - WorkerChoiceStrategies.LESS_USED - ) - expect(strategy).toBeInstanceOf(LessUsedWorkerChoiceStrategy) - }) - - it('Verify that getWorkerChoiceStrategy() can return LESS_BUSY strategy', () => { - const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( - fixedPool - ) - const strategy = workerChoiceStrategyContext.getWorkerChoiceStrategy( - fixedPool, - WorkerChoiceStrategies.LESS_BUSY - ) - expect(strategy).toBeInstanceOf(LessBusyWorkerChoiceStrategy) - }) - - it('Verify that getWorkerChoiceStrategy() can return FAIR_SHARE strategy', () => { - const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( - fixedPool - ) - const strategy = workerChoiceStrategyContext.getWorkerChoiceStrategy( - fixedPool, - WorkerChoiceStrategies.FAIR_SHARE - ) - expect(strategy).toBeInstanceOf(FairShareWorkerChoiceStrategy) - }) - - it('Verify that getWorkerChoiceStrategy() can return WEIGHTED_ROUND_ROBIN strategy', () => { - const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( - fixedPool - ) - const strategy = workerChoiceStrategyContext.getWorkerChoiceStrategy( - fixedPool, - WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN - ) - expect(strategy).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy) - }) - - it('Verify that getWorkerChoiceStrategy() throw error on unknown strategy', () => { - const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( - fixedPool - ) - expect(() => { - workerChoiceStrategyContext.getWorkerChoiceStrategy( - fixedPool, - 'UNKNOWN_STRATEGY' - ) - }).toThrowError( - new Error("Worker choice strategy 'UNKNOWN_STRATEGY' not found") - ) - }) })