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

index 0d4d8116d49d0321c8875a8b24192fa8edad1486..f04013d99c92ad0e61dae665f79df61dda1d2274 100644 (file)
@@ -89,18 +89,31 @@ describe('Worker choice strategy context test suite', () => {
     const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
       fixedPool
     )
-    const WorkerChoiceStrategyStub = sinon.createStubInstance(
+    const WorkerChoiceStrategyUndefinedStub = sinon.createStubInstance(
       RoundRobinWorkerChoiceStrategy,
       {
         choose: sinon.stub().returns(undefined)
       }
     )
+    const WorkerChoiceStrategyNullStub = sinon.createStubInstance(
+      RoundRobinWorkerChoiceStrategy,
+      {
+        choose: sinon.stub().returns(null)
+      }
+    )
     expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
       WorkerChoiceStrategies.ROUND_ROBIN
     )
     workerChoiceStrategyContext.workerChoiceStrategies.set(
       workerChoiceStrategyContext.workerChoiceStrategy,
-      WorkerChoiceStrategyStub
+      WorkerChoiceStrategyUndefinedStub
+    )
+    expect(() => workerChoiceStrategyContext.execute()).toThrowError(
+      new Error('Worker node key chosen is null or undefined')
+    )
+    workerChoiceStrategyContext.workerChoiceStrategies.set(
+      workerChoiceStrategyContext.workerChoiceStrategy,
+      WorkerChoiceStrategyNullStub
     )
     expect(() => workerChoiceStrategyContext.execute()).toThrowError(
       new Error('Worker node key chosen is null or undefined')