})
it('Verify that constructor() initializes the context with all the available worker choice strategies', () => {
- const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
- fixedPool
+ let workerChoiceStrategyContext = new WorkerChoiceStrategyContext(fixedPool)
+ expect(workerChoiceStrategyContext.workerChoiceStrategies.size).toBe(
+ Object.keys(WorkerChoiceStrategies).length
)
+ workerChoiceStrategyContext = new WorkerChoiceStrategyContext(dynamicPool)
expect(workerChoiceStrategyContext.workerChoiceStrategies.size).toBe(
Object.keys(WorkerChoiceStrategies).length
)
})
+ 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() return the worker node key chosen by the strategy with fixed pool', () => {
const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
fixedPool
)
expect(() => workerChoiceStrategyContext.execute()).toThrow(
new Error(
- `Worker node key chosen is null or undefined after ${
- fixedPool.info.maxSize +
- Object.keys(workerChoiceStrategyContext.opts.weights).length
- } retries`
+ `Worker node key chosen is null or undefined after ${workerChoiceStrategyContext.retries} retries`
)
)
const workerChoiceStrategyNullStub = createStubInstance(
)
expect(() => workerChoiceStrategyContext.execute()).toThrow(
new Error(
- `Worker node key chosen is null or undefined after ${
- fixedPool.info.maxSize +
- Object.keys(workerChoiceStrategyContext.opts.weights).length
- } retries`
+ `Worker node key chosen is null or undefined after ${workerChoiceStrategyContext.retries} retries`
)
)
})