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 ${fixedPool.info.maxSize} retries`
+ )
+ )
const workerChoiceStrategyNullStub = createStubInstance(
RoundRobinWorkerChoiceStrategy,
{
choose: stub().returns(null)
}
)
- expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
- WorkerChoiceStrategies.ROUND_ROBIN
- )
- workerChoiceStrategyContext.workerChoiceStrategies.set(
- workerChoiceStrategyContext.workerChoiceStrategy,
- workerChoiceStrategyUndefinedStub
- )
- expect(() => workerChoiceStrategyContext.execute()).toThrow(
- new Error('Worker node key chosen is null or undefined after 6 retries')
- )
workerChoiceStrategyContext.workerChoiceStrategies.set(
workerChoiceStrategyContext.workerChoiceStrategy,
workerChoiceStrategyNullStub
)
expect(() => workerChoiceStrategyContext.execute()).toThrow(
- new Error('Worker node key chosen is null or undefined after 6 retries')
+ new Error(
+ `Worker node key chosen is null or undefined after ${fixedPool.info.maxSize} retries`
+ )
)
})
.returns(false)
.onCall(4)
.returns(false)
- .onCall(6)
- .returns(false)
- .onCall(7)
- .returns(false)
- .onCall(8)
- .returns(false)
.returns(true),
choose: stub().returns(1)
}
workerChoiceStrategyContext.workerChoiceStrategies.get(
workerChoiceStrategyContext.workerChoiceStrategy
).hasPoolWorkerNodesReady.callCount
- ).toBe(12)
+ ).toBe(6)
expect(
workerChoiceStrategyContext.workerChoiceStrategies.get(
workerChoiceStrategyContext.workerChoiceStrategy
expect(chosenWorkerKey).toBe(1)
})
- it('Verify that execute() throws error if worker choice strategy consecutive executions has been reached', () => {
+ it('Verify that execute() throws error if worker choice strategy recursion reach the maximum depth', () => {
const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
fixedPool
)
workerChoiceStrategyStub
)
expect(() => workerChoiceStrategyContext.execute()).toThrow(
- new RangeError(
- 'Worker choice strategy consecutive executions has exceeded the maximum of 10000'
- )
+ new RangeError('Maximum call stack size exceeded')
)
})