X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=tests%2Fpools%2Fselection-strategies%2Fworker-choice-strategy-context.test.js;h=3ce8b9fe040218f9b8e3be0b7a184b87737af0a6;hb=3032893add6cc97da7b0600e21df2865ad1f675c;hp=ae608fda6133a35c88a4b8fc23d5e6586493e891;hpb=c15273f20d0ee8b7b34321f07d7f14e60d1ed895;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 ae608fda..3ce8b9fe 100644 --- a/tests/pools/selection-strategies/worker-choice-strategy-context.test.js +++ b/tests/pools/selection-strategies/worker-choice-strategy-context.test.js @@ -19,7 +19,7 @@ const { } = require('../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy') const { WeightedRoundRobinWorkerChoiceStrategy -} = require('../../../lib/pools/selection-strategies/weighted-round-robin-choice-strategy') +} = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy') const { DynamicPoolWorkerChoiceStrategy } = require('../../../lib/pools/selection-strategies/dynamic-pool-worker-choice-strategy') @@ -45,9 +45,9 @@ describe('Worker choice strategy context test suite', () => { sinon.restore() }) - after(() => { - fixedPool.destroy() - dynamicPool.destroy() + after(async () => { + await fixedPool.destroy() + await dynamicPool.destroy() }) it('Verify that execute() return the worker chosen by the strategy with fixed pool', () => { @@ -61,11 +61,11 @@ describe('Worker choice strategy context test suite', () => { } ) workerChoiceStrategyContext.workerChoiceStrategy = WorkerChoiceStrategyStub - const worker = workerChoiceStrategyContext.execute() + const chosenWorker = workerChoiceStrategyContext.execute() expect( - workerChoiceStrategyContext.workerChoiceStrategy.choose.calledOnce + workerChoiceStrategyContext.getWorkerChoiceStrategy().choose.calledOnce ).toBe(true) - expect(worker).toBe('worker') + expect(chosenWorker).toBe('worker') }) it('Verify that execute() return the worker chosen by the strategy with dynamic pool', () => { @@ -79,11 +79,11 @@ describe('Worker choice strategy context test suite', () => { } ) workerChoiceStrategyContext.workerChoiceStrategy = WorkerChoiceStrategyStub - const worker = workerChoiceStrategyContext.execute() + const chosenWorker = workerChoiceStrategyContext.execute() expect( - workerChoiceStrategyContext.workerChoiceStrategy.choose.calledOnce + workerChoiceStrategyContext.getWorkerChoiceStrategy().choose.calledOnce ).toBe(true) - expect(worker).toBe('worker') + expect(chosenWorker).toBe('worker') }) it('Verify that setWorkerChoiceStrategy() works with ROUND_ROBIN and fixed pool', () => { @@ -93,9 +93,9 @@ describe('Worker choice strategy context test suite', () => { workerChoiceStrategyContext.setWorkerChoiceStrategy( WorkerChoiceStrategies.ROUND_ROBIN ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - RoundRobinWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.getWorkerChoiceStrategy() + ).toBeInstanceOf(RoundRobinWorkerChoiceStrategy) }) it('Verify that setWorkerChoiceStrategy() works with ROUND_ROBIN and dynamic pool', () => { @@ -105,9 +105,12 @@ 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 + ).toBeInstanceOf(RoundRobinWorkerChoiceStrategy) }) it('Verify that setWorkerChoiceStrategy() works with LESS_RECENTLY_USED and fixed pool', () => { @@ -117,9 +120,9 @@ describe('Worker choice strategy context test suite', () => { workerChoiceStrategyContext.setWorkerChoiceStrategy( WorkerChoiceStrategies.LESS_RECENTLY_USED ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - LessRecentlyUsedWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.getWorkerChoiceStrategy() + ).toBeInstanceOf(LessRecentlyUsedWorkerChoiceStrategy) }) it('Verify that setWorkerChoiceStrategy() works with LESS_RECENTLY_USED and dynamic pool', () => { @@ -129,9 +132,12 @@ describe('Worker choice strategy context test suite', () => { workerChoiceStrategyContext.setWorkerChoiceStrategy( WorkerChoiceStrategies.LESS_RECENTLY_USED ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - DynamicPoolWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.getWorkerChoiceStrategy() + ).toBeInstanceOf(DynamicPoolWorkerChoiceStrategy) + expect( + workerChoiceStrategyContext.getWorkerChoiceStrategy().workerChoiceStrategy + ).toBeInstanceOf(LessRecentlyUsedWorkerChoiceStrategy) }) it('Verify that setWorkerChoiceStrategy() works with FAIR_SHARE and fixed pool', () => { @@ -141,9 +147,9 @@ describe('Worker choice strategy context test suite', () => { workerChoiceStrategyContext.setWorkerChoiceStrategy( WorkerChoiceStrategies.FAIR_SHARE ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - FairShareWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.getWorkerChoiceStrategy() + ).toBeInstanceOf(FairShareWorkerChoiceStrategy) }) it('Verify that setWorkerChoiceStrategy() works with FAIR_SHARE and dynamic pool', () => { @@ -153,9 +159,12 @@ 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 + ).toBeInstanceOf(FairShareWorkerChoiceStrategy) }) it('Verify that setWorkerChoiceStrategy() works with WEIGHTED_ROUND_ROBIN and fixed pool', () => { @@ -165,9 +174,9 @@ describe('Worker choice strategy context test suite', () => { workerChoiceStrategyContext.setWorkerChoiceStrategy( WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN ) - expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - WeightedRoundRobinWorkerChoiceStrategy - ) + expect( + workerChoiceStrategyContext.getWorkerChoiceStrategy() + ).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy) }) it('Verify that setWorkerChoiceStrategy() works with WEIGHTED_ROUND_ROBIN and dynamic pool', () => { @@ -177,8 +186,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 + ).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy) }) })