it('Verify that WorkerChoiceStrategies enumeration provides string values', () => {
expect(WorkerChoiceStrategies.ROUND_ROBIN).toBe('ROUND_ROBIN')
expect(WorkerChoiceStrategies.LESS_USED).toBe('LESS_USED')
+ expect(WorkerChoiceStrategies.LESS_BUSY).toBe('LESS_BUSY')
expect(WorkerChoiceStrategies.FAIR_SHARE).toBe('FAIR_SHARE')
expect(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN).toBe(
'WEIGHTED_ROUND_ROBIN'
WorkerChoiceStrategies.ROUND_ROBIN
)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy().nextWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.ROUND_ROBIN
+ ).nextWorkerId
).toBe(0)
// We need to clean up the resources after our test
await pool.destroy()
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+ ).toBe(false)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+ ).toBe(false)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
).toBe(false)
await pool.destroy()
pool = new DynamicThreadPool(
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+ ).toBe(false)
+ 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()
)
let results = new Set()
for (let i = 0; i < max; i++) {
- results.add(pool.chooseWorker().id)
+ results.add(pool.chooseWorker()[1].id)
}
expect(results.size).toBe(max)
await pool.destroy()
pool = new FixedThreadPool(max, './tests/worker-files/thread/testWorker.js')
results = new Set()
for (let i = 0; i < max; i++) {
- results.add(pool.chooseWorker().threadId)
+ results.add(pool.chooseWorker()[1].threadId)
}
expect(results.size).toBe(max)
await pool.destroy()
{ workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy().nextWorkerId
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.ROUND_ROBIN
+ ).nextWorkerId
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy().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.getWorkerChoiceStrategy()
- .workerChoiceStrategy.nextWorkerId
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.ROUND_ROBIN
+ ).nextWorkerId
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .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()
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_USED)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+ ).toBe(false)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+ ).toBe(false)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
).toBe(false)
await pool.destroy()
pool = new DynamicThreadPool(
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_USED)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+ ).toBe(false)
+ 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()
'./tests/worker-files/thread/testWorker.js',
{ workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
)
- // TODO: Create a better test to cover `LessRecentlyUsedWorkerChoiceStrategy#choose`
+ // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
const promises = []
for (let i = 0; i < max * 2; i++) {
promises.push(pool.execute())
'./tests/worker-files/thread/testWorker.js',
{ workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
)
- // TODO: Create a better test to cover `LessRecentlyUsedWorkerChoiceStrategy#choose`
+ // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
+ const promises = []
+ for (let i = 0; i < max * 2; i++) {
+ promises.push(pool.execute())
+ }
+ await Promise.all(promises)
+ // We need to clean up the resources after our test
+ await pool.destroy()
+ })
+
+ it('Verify LESS_BUSY strategy is taken at pool creation', async () => {
+ const pool = new FixedThreadPool(
+ max,
+ './tests/worker-files/thread/testWorker.js',
+ { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
+ )
+ expect(pool.opts.workerChoiceStrategy).toBe(
+ WorkerChoiceStrategies.LESS_BUSY
+ )
+ // We need to clean up the resources after our test
+ await pool.destroy()
+ })
+
+ it('Verify LESS_BUSY strategy can be set after pool creation', async () => {
+ const pool = new FixedThreadPool(
+ max,
+ './tests/worker-files/thread/testWorker.js'
+ )
+ pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_BUSY)
+ expect(pool.opts.workerChoiceStrategy).toBe(
+ WorkerChoiceStrategies.LESS_BUSY
+ )
+ // We need to clean up the resources after our test
+ await pool.destroy()
+ })
+
+ it('Verify LESS_BUSY strategy default tasks usage statistics requirements', async () => {
+ let pool = new FixedThreadPool(
+ max,
+ './tests/worker-files/thread/testWorker.js'
+ )
+ pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_BUSY)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+ ).toBe(true)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+ ).toBe(false)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+ ).toBe(false)
+ await pool.destroy()
+ pool = new DynamicThreadPool(
+ min,
+ max,
+ './tests/worker-files/thread/testWorker.js'
+ )
+ pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_BUSY)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+ ).toBe(true)
+ 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()
+ })
+
+ it('Verify LESS_BUSY strategy can be run in a fixed pool', async () => {
+ const pool = new FixedThreadPool(
+ max,
+ './tests/worker-files/thread/testWorker.js',
+ { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
+ )
+ // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
+ const promises = []
+ for (let i = 0; i < max * 2; i++) {
+ promises.push(pool.execute())
+ }
+ await Promise.all(promises)
+ // We need to clean up the resources after our test
+ await pool.destroy()
+ })
+
+ it('Verify LESS_BUSY strategy can be run in a dynamic pool', async () => {
+ const pool = new DynamicThreadPool(
+ min,
+ max,
+ './tests/worker-files/thread/testWorker.js',
+ { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
+ )
+ // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
const promises = []
for (let i = 0; i < max * 2; i++) {
promises.push(pool.execute())
expect(pool.opts.workerChoiceStrategy).toBe(
WorkerChoiceStrategies.FAIR_SHARE
)
- for (const worker of pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
.workerLastVirtualTaskTimestamp.keys()) {
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerLastVirtualTaskTimestamp.get(worker).start
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
+ .workerLastVirtualTaskTimestamp.get(workerKey).start
).toBe(0)
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerLastVirtualTaskTimestamp.get(worker).end
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
+ .workerLastVirtualTaskTimestamp.get(workerKey).end
).toBe(0)
}
// We need to clean up the resources after our test
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
).toBe(true)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+ ).toBe(true)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+ ).toBe(false)
await pool.destroy()
pool = new DynamicThreadPool(
min,
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+ ).toBe(true)
+ 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()
})
promises.push(pool.execute())
}
await Promise.all(promises)
+ expect(
+ 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()
})
)
// TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
const promises = []
- for (let i = 0; i < max * 2; i++) {
+ const maxMultiplier = 2
+ for (let i = 0; i < max * maxMultiplier; i++) {
promises.push(pool.execute())
}
await Promise.all(promises)
+ // if (process.platform !== 'win32') {
+ // expect(
+ // 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()
})
'./tests/worker-files/thread/testWorker.js'
)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workerLastVirtualTaskTimestamp
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.FAIR_SHARE
+ ).workerLastVirtualTaskTimestamp
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
- for (const worker of pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
.workerLastVirtualTaskTimestamp.keys()) {
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerLastVirtualTaskTimestamp.get(worker).start
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
+ .workerLastVirtualTaskTimestamp.get(workerKey).start
).toBe(0)
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerLastVirtualTaskTimestamp.get(worker).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.getWorkerChoiceStrategy()
- .workerChoiceStrategy.workerLastVirtualTaskTimestamp
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.FAIR_SHARE
+ ).workerLastVirtualTaskTimestamp
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
- for (const worker of pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) {
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
+ .workerLastVirtualTaskTimestamp.keys()) {
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(worker).start
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.FAIR_SHARE)
+ .workerLastVirtualTaskTimestamp.get(workerKey).start
).toBe(0)
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(worker).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.getWorkerChoiceStrategy().currentWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).currentWorkerId
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .defaultWorkerWeight
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).defaultWorkerWeight
).toBeGreaterThan(0)
- for (const worker of pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
.workersTaskRunTime.keys()) {
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workersTaskRunTime.get(worker).weight
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+ .workersTaskRunTime.get(workerKey).weight
).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workersTaskRunTime.get(worker).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
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+ ).toBe(true)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
).toBe(true)
+ expect(
+ pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+ ).toBe(false)
await pool.destroy()
pool = new DynamicThreadPool(
min,
)
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
+ pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+ ).toBe(true)
+ 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()
})
promises.push(pool.execute())
}
await Promise.all(promises)
+ expect(
+ 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 = []
- for (let i = 0; i < max * 2; i++) {
+ const maxMultiplier =
+ 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.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()
})
'./tests/worker-files/thread/testWorker.js'
)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy().currentWorkerId
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).currentWorkerId
+ ).toBeDefined()
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .defaultWorkerWeight
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).defaultWorkerWeight
+ ).toBeDefined()
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workersTaskRunTime
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).workersTaskRunTime
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy().currentWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).currentWorkerId
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .defaultWorkerWeight
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).defaultWorkerWeight
).toBeGreaterThan(0)
- for (const worker of pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
.workersTaskRunTime.keys()) {
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workersTaskRunTime.get(worker).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.getWorkerChoiceStrategy()
- .workerChoiceStrategy.currentWorkerId
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).currentWorkerId
+ ).toBeDefined()
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workerChoiceStrategy.defaultWorkerWeight
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).defaultWorkerWeight
+ ).toBeDefined()
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workerChoiceStrategy.workersTaskRunTime
- ).toBeUndefined()
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).workersTaskRunTime
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workerChoiceStrategy.currentWorkerId
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).currentWorkerId
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .workerChoiceStrategy.defaultWorkerWeight
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ ).defaultWorkerWeight
).toBeGreaterThan(0)
- for (const worker of pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerChoiceStrategy.workersTaskRunTime.keys()) {
+ for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+ .workersTaskRunTime.keys()) {
expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workerChoiceStrategy.workersTaskRunTime.get(worker).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'")
)
})
})