)
})
- it('Verify that execute() return the worker node key chosen by the strategy with fixed pool', () => {
- const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
- fixedPool
- )
- const workerChoiceStrategyStub = createStubInstance(
- RoundRobinWorkerChoiceStrategy,
- {
- hasPoolWorkerNodesReady: stub().returns(true),
- choose: stub().returns(0)
- }
- )
- expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
- WorkerChoiceStrategies.ROUND_ROBIN
- )
- workerChoiceStrategyContext.workerChoiceStrategies.set(
- workerChoiceStrategyContext.workerChoiceStrategy,
- workerChoiceStrategyStub
- )
- const chosenWorkerKey = workerChoiceStrategyContext.execute()
- expect(
- workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategyContext.workerChoiceStrategy
- ).choose.calledOnce
- ).toBe(true)
- expect(chosenWorkerKey).toBe(0)
- })
-
it('Verify that execute() throws error if null or undefined is returned after retries', () => {
const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
fixedPool
const workerChoiceStrategyUndefinedStub = createStubInstance(
RoundRobinWorkerChoiceStrategy,
{
- hasPoolWorkerNodesReady: stub().returns(true),
choose: stub().returns(undefined)
}
)
const workerChoiceStrategyNullStub = createStubInstance(
RoundRobinWorkerChoiceStrategy,
{
- hasPoolWorkerNodesReady: stub().returns(true),
choose: stub().returns(null)
}
)
)
})
- it('Verify that execute() retry until a worker node is ready and chosen', () => {
+ it('Verify that execute() retry until a worker node is chosen', () => {
const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
fixedPool
)
const workerChoiceStrategyStub = createStubInstance(
RoundRobinWorkerChoiceStrategy,
{
- hasPoolWorkerNodesReady: stub()
+ choose: stub()
.onCall(0)
- .returns(false)
+ .returns(undefined)
.onCall(1)
- .returns(false)
+ .returns(undefined)
.onCall(2)
- .returns(false)
+ .returns(undefined)
.onCall(3)
- .returns(false)
+ .returns(undefined)
.onCall(4)
- .returns(false)
- .returns(true),
- choose: stub().returns(1)
+ .returns(undefined)
+ .returns(1)
}
)
expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
workerChoiceStrategyContext.workerChoiceStrategies.get(
workerChoiceStrategyContext.workerChoiceStrategy
).choose.callCount
- ).toBe(1)
+ ).toBe(6)
expect(chosenWorkerKey).toBe(1)
})
+ it('Verify that execute() return the worker node key chosen by the strategy with fixed pool', () => {
+ const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+ fixedPool
+ )
+ const workerChoiceStrategyStub = createStubInstance(
+ RoundRobinWorkerChoiceStrategy,
+ {
+ choose: stub().returns(0)
+ }
+ )
+ expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
+ WorkerChoiceStrategies.ROUND_ROBIN
+ )
+ workerChoiceStrategyContext.workerChoiceStrategies.set(
+ workerChoiceStrategyContext.workerChoiceStrategy,
+ workerChoiceStrategyStub
+ )
+ const chosenWorkerKey = workerChoiceStrategyContext.execute()
+ expect(
+ workerChoiceStrategyContext.workerChoiceStrategies.get(
+ workerChoiceStrategyContext.workerChoiceStrategy
+ ).choose.calledOnce
+ ).toBe(true)
+ expect(chosenWorkerKey).toBe(0)
+ })
+
it('Verify that execute() return the worker node key chosen by the strategy with dynamic pool', () => {
const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
dynamicPool
const workerChoiceStrategyStub = createStubInstance(
RoundRobinWorkerChoiceStrategy,
{
- hasPoolWorkerNodesReady: stub().returns(true),
choose: stub().returns(0)
}
)