WorkerChoiceStrategies.ROUND_ROBIN
)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.ROUND_ROBIN
+ ).nextWorkerId
).toBe(0)
// We need to clean up the resources after our test
await pool.destroy()
expect(
pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
).toBe(false)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+ ).toBe(false)
await pool.destroy()
pool = new DynamicThreadPool(
min,
expect(
pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
).toBe(false)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+ ).toBe(false)
// We need to clean up the resources after our test
await pool.destroy()
})
{ workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.ROUND_ROBIN
+ ).nextWorkerId
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.ROUND_ROBIN
+ ).nextWorkerId
).toBe(0)
await pool.destroy()
pool = new DynamicThreadPool(
{ workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.ROUND_ROBIN
+ ).nextWorkerId
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.ROUND_ROBIN
+ ).nextWorkerId
).toBe(0)
// We need to clean up the resources after our test
await pool.destroy()
expect(
pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
).toBe(false)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+ ).toBe(false)
await pool.destroy()
pool = new DynamicThreadPool(
min,
expect(
pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
).toBe(false)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+ ).toBe(false)
// We need to clean up the resources after our test
await pool.destroy()
})
expect(
pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
).toBe(false)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+ ).toBe(false)
await pool.destroy()
pool = new DynamicThreadPool(
min,
expect(
pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
).toBe(false)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+ ).toBe(false)
// 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.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) {
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
+ .workerLastVirtualTaskTimestamp.keys()) {
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
- workerKey
- ).start
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
+ .workerLastVirtualTaskTimestamp.get(workerKey).start
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
- workerKey
- ).end
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
+ .workerLastVirtualTaskTimestamp.get(workerKey).end
).toBe(0)
}
// We need to clean up the resources after our test
expect(
pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
).toBe(true)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+ ).toBe(false)
await pool.destroy()
pool = new DynamicThreadPool(
min,
expect(
pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
).toBe(true)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+ ).toBe(false)
// We need to clean up the resources after our test
await pool.destroy()
})
}
await Promise.all(promises)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- .workerLastVirtualTaskTimestamp.size
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.FAIR_SHARE
+ ).workerLastVirtualTaskTimestamp.size
).toBe(pool.workers.length)
// We need to clean up the resources after our test
await pool.destroy()
await Promise.all(promises)
// if (process.platform !== 'win32') {
// expect(
- // pool.workerChoiceStrategyContext.workerChoiceStrategy
- // .workerLastVirtualTaskTimestamp.size
+ // pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ // WorkerChoiceStrategies.FAIR_SHARE
+ // ).workerLastVirtualTaskTimestamp.size
// ).toBe(pool.workers.length)
// }
// We need to clean up the resources after our test
'./tests/worker-files/thread/testWorker.js'
)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- .workerLastVirtualTaskTimestamp
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.FAIR_SHARE
+ ).workerLastVirtualTaskTimestamp
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
- for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) {
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
+ .workerLastVirtualTaskTimestamp.keys()) {
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
- workerKey
- ).start
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
+ .workerLastVirtualTaskTimestamp.get(workerKey).start
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
- workerKey
- ).end
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
+ .workerLastVirtualTaskTimestamp.get(workerKey).end
).toBe(0)
}
await pool.destroy()
'./tests/worker-files/thread/testWorker.js'
)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- .workerLastVirtualTaskTimestamp
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.FAIR_SHARE
+ ).workerLastVirtualTaskTimestamp
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
- for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) {
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
+ .workerLastVirtualTaskTimestamp.keys()) {
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
- workerKey
- ).start
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
+ .workerLastVirtualTaskTimestamp.get(workerKey).start
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
- workerKey
- ).end
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
+ .workerLastVirtualTaskTimestamp.get(workerKey).end
).toBe(0)
}
// We need to clean up the resources after our test
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).currentWorkerId
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).defaultWorkerWeight
).toBeGreaterThan(0)
- for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.keys()) {
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+ .workersTaskRunTime.keys()) {
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get(
- workerKey
- ).weight
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+ .workersTaskRunTime.get(workerKey).weight
).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get(
- workerKey
- ).runTime
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+ .workersTaskRunTime.get(workerKey).runTime
).toBe(0)
}
// We need to clean up the resources after our test
expect(
pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
).toBe(true)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+ ).toBe(false)
await pool.destroy()
pool = new DynamicThreadPool(
min,
expect(
pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
).toBe(true)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+ ).toBe(false)
// We need to clean up the resources after our test
await pool.destroy()
})
}
await Promise.all(promises)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime
- .size
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).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 = []
const maxMultiplier =
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- .defaultWorkerWeight * 2
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).defaultWorkerWeight * 50
for (let i = 0; i < max * maxMultiplier; i++) {
promises.push(pool.execute())
}
await Promise.all(promises)
if (process.platform !== 'win32') {
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime
- .size
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).workersTaskRunTime.size
).toBe(pool.workers.length)
}
// We need to clean up the resources after our test
'./tests/worker-files/thread/testWorker.js'
)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).currentWorkerId
+ ).toBeDefined()
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).defaultWorkerWeight
+ ).toBeDefined()
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).workersTaskRunTime
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).currentWorkerId
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).defaultWorkerWeight
).toBeGreaterThan(0)
- for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.keys()) {
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+ .workersTaskRunTime.keys()) {
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get(
- workerKey
- ).runTime
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+ .workersTaskRunTime.get(workerKey).runTime
).toBe(0)
}
await pool.destroy()
'./tests/worker-files/thread/testWorker.js'
)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).currentWorkerId
+ ).toBeDefined()
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).defaultWorkerWeight
+ ).toBeDefined()
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).workersTaskRunTime
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).currentWorkerId
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).defaultWorkerWeight
).toBeGreaterThan(0)
- for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.keys()) {
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+ .workersTaskRunTime.keys()) {
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get(
- workerKey
- ).runTime
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+ .workersTaskRunTime.get(workerKey).runTime
).toBe(0)
}
// We need to clean up the resources after our test
{ workerChoiceStrategy: 'UNKNOWN_STRATEGY' }
)
).toThrowError(
- new Error("Worker choice strategy 'UNKNOWN_STRATEGY' not found")
+ new Error("Invalid worker choice strategy 'UNKNOWN_STRATEGY'")
)
})
})