+ it('Verify that constructor() initializes the context with retries attribute properly set', () => {
+ let workerChoiceStrategyContext = new WorkerChoiceStrategyContext(fixedPool)
+ expect(workerChoiceStrategyContext.retries).toBe(fixedPool.info.maxSize * 2)
+ workerChoiceStrategyContext = new WorkerChoiceStrategyContext(dynamicPool)
+ expect(workerChoiceStrategyContext.retries).toBe(
+ dynamicPool.info.maxSize * 2
+ )
+ })
+
+ it('Verify that execute() throws error if null or undefined is returned after retries', () => {
+ const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+ fixedPool
+ )
+ expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
+ WorkerChoiceStrategies.ROUND_ROBIN
+ )
+ const workerChoiceStrategyUndefinedStub = createStubInstance(
+ RoundRobinWorkerChoiceStrategy,
+ {
+ 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', () => {