+ choose: stub().returns(undefined)
+ }
+ )
+ workerChoiceStrategyContext.workerChoiceStrategies.set(
+ workerChoiceStrategyContext.workerChoiceStrategy,
+ workerChoiceStrategyUndefinedStub
+ )
+ expect(() => workerChoiceStrategyContext.execute()).toThrow(
+ new Error(
+ `Worker node key chosen is null or undefined after ${workerChoiceStrategyContext.retries} retries`
+ )
+ )
+ const workerChoiceStrategyNullStub = createStubInstance(
+ RoundRobinWorkerChoiceStrategy,
+ {
+ choose: stub().returns(null)
+ }
+ )
+ workerChoiceStrategyContext.workerChoiceStrategies.set(
+ workerChoiceStrategyContext.workerChoiceStrategy,
+ workerChoiceStrategyNullStub
+ )
+ expect(() => workerChoiceStrategyContext.execute()).toThrow(
+ new Error(
+ `Worker node key chosen is null or undefined after ${workerChoiceStrategyContext.retries} retries`
+ )
+ )
+ })
+
+ it('Verify that execute() retry until a worker node is chosen', () => {
+ const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+ fixedPool
+ )
+ const workerChoiceStrategyStub = createStubInstance(
+ RoundRobinWorkerChoiceStrategy,
+ {
+ choose: stub()
+ .onCall(0)
+ .returns(undefined)
+ .onCall(1)
+ .returns(undefined)
+ .onCall(2)
+ .returns(undefined)
+ .onCall(3)
+ .returns(undefined)
+ .onCall(4)
+ .returns(undefined)
+ .returns(1)