WorkerChoiceStrategies.ROUND_ROBIN
)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy().nextWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId
).toBe(0)
// We need to clean up the resources after our test
await pool.destroy()
{ workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy().nextWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId
).toBeUndefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy().nextWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId
).toBe(0)
await pool.destroy()
pool = new DynamicThreadPool(
{ workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workerChoiceStrategy.nextWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
+ .nextWorkerId
).toBeUndefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workerChoiceStrategy.nextWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
+ .nextWorkerId
).toBe(0)
// We need to clean up the resources after our test
await pool.destroy()
expect(pool.opts.workerChoiceStrategy).toBe(
WorkerChoiceStrategies.FAIR_SHARE
)
- for (const workerKey of pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerLastVirtualTaskTimestamp.keys()) {
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) {
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerLastVirtualTaskTimestamp.get(workerKey).start
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
+ workerKey
+ ).start
).toBe(0)
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerLastVirtualTaskTimestamp.get(workerKey).end
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
+ workerKey
+ ).end
).toBe(0)
}
// We need to clean up the resources after our test
}
await Promise.all(promises)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
+ pool.workerChoiceStrategyContext.workerChoiceStrategy
.workerLastVirtualTaskTimestamp.size
).toBe(pool.workers.length)
// We need to clean up the resources after our test
promises.push(pool.execute())
}
await Promise.all(promises)
- // expect(
- // pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- // .workerChoiceStrategy.workerLastVirtualTaskTimestamp.size
- // ).toBe(pool.workers.length)
+ expect(
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
+ .workerLastVirtualTaskTimestamp.size
+ ).toBe(pool.workers.length)
// We need to clean up the resources after our test
await pool.destroy()
})
'./tests/worker-files/thread/testWorker.js'
)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
+ pool.workerChoiceStrategyContext.workerChoiceStrategy
.workerLastVirtualTaskTimestamp
).toBeUndefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
- for (const workerKey of pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerLastVirtualTaskTimestamp.keys()) {
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) {
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerLastVirtualTaskTimestamp.get(workerKey).start
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
+ workerKey
+ ).start
).toBe(0)
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerLastVirtualTaskTimestamp.get(workerKey).end
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
+ workerKey
+ ).end
).toBe(0)
}
await pool.destroy()
'./tests/worker-files/thread/testWorker.js'
)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workerChoiceStrategy.workerLastVirtualTaskTimestamp
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
+ .workerLastVirtualTaskTimestamp
).toBeUndefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
- for (const workerKey of pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) {
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) {
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(workerKey)
- .start
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
+ workerKey
+ ).start
).toBe(0)
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(workerKey)
- .end
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
+ workerKey
+ ).end
).toBe(0)
}
// We need to clean up the resources after our test
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy().currentWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .defaultWorkerWeight
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight
).toBeGreaterThan(0)
- for (const workerKey of pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workersTaskRunTime.keys()) {
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.keys()) {
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workersTaskRunTime.get(workerKey).weight
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get(
+ workerKey
+ ).weight
).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workersTaskRunTime.get(workerKey).runTime
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get(
+ workerKey
+ ).runTime
).toBe(0)
}
// We need to clean up the resources after our test
}
await Promise.all(promises)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workersTaskRunTime.size
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime
+ .size
).toBe(pool.workers.length)
// We need to clean up the resources after our test
await pool.destroy()
)
// TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
const promises = []
- for (let i = 0; i < max * 2; i++) {
+ const maxMultiplier =
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
+ .defaultWorkerWeight
+ for (let i = 0; i < max * maxMultiplier; i++) {
promises.push(pool.execute())
}
await Promise.all(promises)
- // expect(
- // pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- // .workerChoiceStrategy.workersTaskRunTime.size
- // ).toBe(pool.workers.length)
+ expect(
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
+ .workersTaskRunTime.size
+ ).toBe(pool.workers.length)
// We need to clean up the resources after our test
await pool.destroy()
})
'./tests/worker-files/thread/testWorker.js'
)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy().currentWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId
).toBeUndefined()
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .defaultWorkerWeight
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight
).toBeUndefined()
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workersTaskRunTime
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime
).toBeUndefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy().currentWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .defaultWorkerWeight
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight
).toBeGreaterThan(0)
- for (const workerKey of pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workersTaskRunTime.keys()) {
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.keys()) {
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workersTaskRunTime.get(workerKey).runTime
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get(
+ workerKey
+ ).runTime
).toBe(0)
}
await pool.destroy()
'./tests/worker-files/thread/testWorker.js'
)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workerChoiceStrategy.currentWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
+ .currentWorkerId
).toBeUndefined()
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workerChoiceStrategy.defaultWorkerWeight
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
+ .defaultWorkerWeight
).toBeUndefined()
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workerChoiceStrategy.workersTaskRunTime
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
+ .workersTaskRunTime
).toBeUndefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workerChoiceStrategy.currentWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
+ .currentWorkerId
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workerChoiceStrategy.defaultWorkerWeight
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
+ .defaultWorkerWeight
).toBeGreaterThan(0)
- for (const workerKey of pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerChoiceStrategy.workersTaskRunTime.keys()) {
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workersTaskRunTime.keys()) {
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerChoiceStrategy.workersTaskRunTime.get(workerKey).runTime
+ pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workersTaskRunTime.get(
+ workerKey
+ ).runTime
).toBe(0)
}
// We need to clean up the resources after our test
workerChoiceStrategyContext.workerChoiceStrategy = WorkerChoiceStrategyStub
const chosenWorkerKey = workerChoiceStrategyContext.execute()
expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy().choose.calledOnce
+ workerChoiceStrategyContext.workerChoiceStrategy.choose.calledOnce
).toBe(true)
expect(chosenWorkerKey).toBe(0)
})
workerChoiceStrategyContext.workerChoiceStrategy = WorkerChoiceStrategyStub
const chosenWorkerKey = workerChoiceStrategyContext.execute()
expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy().choose.calledOnce
+ workerChoiceStrategyContext.workerChoiceStrategy.choose.calledOnce
).toBe(true)
expect(chosenWorkerKey).toBe(0)
})
workerChoiceStrategyContext.setWorkerChoiceStrategy(
WorkerChoiceStrategies.ROUND_ROBIN
)
- expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy()
- ).toBeInstanceOf(RoundRobinWorkerChoiceStrategy)
+ expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf(
+ RoundRobinWorkerChoiceStrategy
+ )
})
it('Verify that setWorkerChoiceStrategy() works with ROUND_ROBIN and dynamic pool', () => {
workerChoiceStrategyContext.setWorkerChoiceStrategy(
WorkerChoiceStrategies.ROUND_ROBIN
)
+ expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf(
+ DynamicPoolWorkerChoiceStrategy
+ )
expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy()
- ).toBeInstanceOf(DynamicPoolWorkerChoiceStrategy)
- expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy().workerChoiceStrategy
+ workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
).toBeInstanceOf(RoundRobinWorkerChoiceStrategy)
})
workerChoiceStrategyContext.setWorkerChoiceStrategy(
WorkerChoiceStrategies.LESS_USED
)
- expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy()
- ).toBeInstanceOf(LessUsedWorkerChoiceStrategy)
+ expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf(
+ LessUsedWorkerChoiceStrategy
+ )
})
it('Verify that setWorkerChoiceStrategy() works with LESS_USED and dynamic pool', () => {
workerChoiceStrategyContext.setWorkerChoiceStrategy(
WorkerChoiceStrategies.LESS_USED
)
+ expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf(
+ DynamicPoolWorkerChoiceStrategy
+ )
expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy()
- ).toBeInstanceOf(DynamicPoolWorkerChoiceStrategy)
- expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy().workerChoiceStrategy
+ workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
).toBeInstanceOf(LessUsedWorkerChoiceStrategy)
})
workerChoiceStrategyContext.setWorkerChoiceStrategy(
WorkerChoiceStrategies.LESS_BUSY
)
- expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy()
- ).toBeInstanceOf(LessBusyWorkerChoiceStrategy)
+ expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf(
+ LessBusyWorkerChoiceStrategy
+ )
})
it('Verify that setWorkerChoiceStrategy() works with LESS_BUSY and dynamic pool', () => {
workerChoiceStrategyContext.setWorkerChoiceStrategy(
WorkerChoiceStrategies.LESS_BUSY
)
+ expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf(
+ DynamicPoolWorkerChoiceStrategy
+ )
expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy()
- ).toBeInstanceOf(DynamicPoolWorkerChoiceStrategy)
- expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy().workerChoiceStrategy
+ workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
).toBeInstanceOf(LessBusyWorkerChoiceStrategy)
})
workerChoiceStrategyContext.setWorkerChoiceStrategy(
WorkerChoiceStrategies.FAIR_SHARE
)
- expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy()
- ).toBeInstanceOf(FairShareWorkerChoiceStrategy)
+ expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf(
+ FairShareWorkerChoiceStrategy
+ )
})
it('Verify that setWorkerChoiceStrategy() works with FAIR_SHARE and dynamic pool', () => {
workerChoiceStrategyContext.setWorkerChoiceStrategy(
WorkerChoiceStrategies.FAIR_SHARE
)
+ expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf(
+ DynamicPoolWorkerChoiceStrategy
+ )
expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy()
- ).toBeInstanceOf(DynamicPoolWorkerChoiceStrategy)
- expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy().workerChoiceStrategy
+ workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
).toBeInstanceOf(FairShareWorkerChoiceStrategy)
})
workerChoiceStrategyContext.setWorkerChoiceStrategy(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
)
- expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy()
- ).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy)
+ expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf(
+ WeightedRoundRobinWorkerChoiceStrategy
+ )
})
it('Verify that setWorkerChoiceStrategy() works with WEIGHTED_ROUND_ROBIN and dynamic pool', () => {
workerChoiceStrategyContext.setWorkerChoiceStrategy(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
)
+ expect(workerChoiceStrategyContext.workerChoiceStrategy).toBeInstanceOf(
+ DynamicPoolWorkerChoiceStrategy
+ )
expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy()
- ).toBeInstanceOf(DynamicPoolWorkerChoiceStrategy)
- expect(
- workerChoiceStrategyContext.getWorkerChoiceStrategy().workerChoiceStrategy
+ workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy)
})
})