test: test for undefined worker node key chosen
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 8 May 2023 09:12:47 +0000 (11:12 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 8 May 2023 09:12:47 +0000 (11:12 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
tests/pools/selection-strategies/worker-choice-strategy-context.test.js

index 060ebb63f352594c706ffac7f51e0f63c56a44f0..0d4d8116d49d0321c8875a8b24192fa8edad1486 100644 (file)
@@ -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