refactor: spell fixes
[poolifier.git] / tests / pools / selection-strategies / worker-choice-strategy-context.test.js
index 060ebb63f352594c706ffac7f51e0f63c56a44f0..fa380a5ae4320f0f4056bd48462e940992c60288 100644 (file)
@@ -85,6 +85,41 @@ 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 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,
+      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')
+    )
+  })
+
   it('Verify that execute() return the worker chosen by the strategy with dynamic pool', () => {
     const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
       dynamicPool
@@ -287,7 +322,7 @@ describe('Worker choice strategy context test suite', () => {
     )
   })
 
-  it('Verify that worker choice strategy options enable median run time pool statistics', () => {
+  it('Verify that worker choice strategy options enable median runtime pool statistics', () => {
     const wwrWorkerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
     let workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
       fixedPool,