X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fselection-strategies%2Fworker-choice-strategy-context.test.js;h=c30bda737d35637f2b88020f0ed8441a0fb5c020;hb=7fd82a1cb4d9d43e0f44333db35d3c4ad694e010;hp=017d7db2cdb5ce2d04f6d2da48a5308ab60b8605;hpb=23ff945ac0bc3b9bcf98c6491872cffaac805b73;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 017d7db2..c30bda73 100644 --- a/tests/pools/selection-strategies/worker-choice-strategy-context.test.js +++ b/tests/pools/selection-strategies/worker-choice-strategy-context.test.js @@ -17,24 +17,39 @@ const { const { FairShareWorkerChoiceStrategy } = require('../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy') -// const { -// WeightedRoundRobinWorkerChoiceStrategy -// } = require('../../../lib/pools/selection-strategies/weighted-round-robin-choice-strategy') +const { + WeightedRoundRobinWorkerChoiceStrategy +} = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy') const { DynamicPoolWorkerChoiceStrategy } = require('../../../lib/pools/selection-strategies/dynamic-pool-worker-choice-strategy') describe('Worker choice strategy context test suite', () => { + const min = 1 + const max = 3 let fixedPool, dynamicPool - beforeEach(() => { - fixedPool = sinon.createStubInstance(FixedThreadPool) - dynamicPool = sinon.createStubInstance(DynamicThreadPool) + + before(() => { + fixedPool = new FixedThreadPool( + max, + './tests/worker-files/thread/testWorker.js' + ) + dynamicPool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js' + ) }) afterEach(() => { sinon.restore() }) + after(async () => { + await fixedPool.destroy() + await dynamicPool.destroy() + }) + it('Verify that execute() return the worker chosen by the strategy with fixed pool', () => { const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool @@ -93,6 +108,9 @@ describe('Worker choice strategy context test suite', () => { expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( DynamicPoolWorkerChoiceStrategy ) + expect( + workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy + ).toBeInstanceOf(RoundRobinWorkerChoiceStrategy) }) it('Verify that setWorkerChoiceStrategy() works with LESS_RECENTLY_USED and fixed pool', () => { @@ -117,6 +135,9 @@ describe('Worker choice strategy context test suite', () => { expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( DynamicPoolWorkerChoiceStrategy ) + expect( + workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy + ).toBeInstanceOf(LessRecentlyUsedWorkerChoiceStrategy) }) it('Verify that setWorkerChoiceStrategy() works with FAIR_SHARE and fixed pool', () => { @@ -141,29 +162,35 @@ describe('Worker choice strategy context test suite', () => { expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( DynamicPoolWorkerChoiceStrategy ) + expect( + workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy + ).toBeInstanceOf(FairShareWorkerChoiceStrategy) }) - // it('Verify that setWorkerChoiceStrategy() works with WEIGHTED_ROUND_ROBIN and fixed pool', () => { - // const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( - // fixedPool - // ) - // workerChoiceStrategyContext.setWorkerChoiceStrategy( - // WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN - // ) - // expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - // WeightedRoundRobinWorkerChoiceStrategy - // ) - // }) + it('Verify that setWorkerChoiceStrategy() works with WEIGHTED_ROUND_ROBIN and fixed pool', () => { + const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( + fixedPool + ) + workerChoiceStrategyContext.setWorkerChoiceStrategy( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( + WeightedRoundRobinWorkerChoiceStrategy + ) + }) - // it('Verify that setWorkerChoiceStrategy() works with WEIGHTED_ROUND_ROBIN and dynamic pool', () => { - // const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( - // dynamicPool - // ) - // workerChoiceStrategyContext.setWorkerChoiceStrategy( - // WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN - // ) - // expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( - // DynamicPoolWorkerChoiceStrategy - // ) - // }) + it('Verify that setWorkerChoiceStrategy() works with WEIGHTED_ROUND_ROBIN and dynamic pool', () => { + const workerChoiceStrategyContext = new WorkerChoiceStrategyContext( + dynamicPool + ) + workerChoiceStrategyContext.setWorkerChoiceStrategy( + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + ) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf( + DynamicPoolWorkerChoiceStrategy + ) + expect( + workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy + ).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy) + }) })