From: Jérôme Benoit Date: Mon, 8 May 2023 09:12:47 +0000 (+0200) Subject: test: test for undefined worker node key chosen X-Git-Tag: v2.4.13~9 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=527e715f3850ddf116073a97a8bc2f7c6f9a6b86;p=poolifier.git test: test for undefined worker node key chosen Signed-off-by: Jérôme Benoit --- 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 060ebb63f..0d4d8116d 100644 --- a/tests/pools/selection-strategies/worker-choice-strategy-context.test.js +++ b/tests/pools/selection-strategies/worker-choice-strategy-context.test.js @@ -85,6 +85,28 @@ 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 WorkerChoiceStrategyStub = sinon.createStubInstance( + RoundRobinWorkerChoiceStrategy, + { + choose: sinon.stub().returns(undefined) + } + ) + expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe( + WorkerChoiceStrategies.ROUND_ROBIN + ) + workerChoiceStrategyContext.workerChoiceStrategies.set( + workerChoiceStrategyContext.workerChoiceStrategy, + WorkerChoiceStrategyStub + ) + 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