From 527e715f3850ddf116073a97a8bc2f7c6f9a6b86 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 8 May 2023 11:12:47 +0200 Subject: [PATCH] test: test for undefined worker node key chosen MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../worker-choice-strategy-context.test.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 060ebb63..0d4d8116 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 -- 2.34.1