expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.ROUND_ROBIN
- ).nextWorkerId
+ ).nextWorkerNodeId
).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()
})
)
let results = new Set()
for (let i = 0; i < max; i++) {
- results.add(pool.chooseWorker()[1].id)
+ results.add(pool.chooseWorkerNode()[1].worker.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()[1].threadId)
+ results.add(pool.chooseWorkerNode()[1].worker.threadId)
}
expect(results.size).toBe(max)
await pool.destroy()
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.ROUND_ROBIN
- )?.nextWorkerId
- ).toBeUndefined()
+ ).nextWorkerNodeId
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.ROUND_ROBIN
- ).nextWorkerId
+ ).nextWorkerNodeId
).toBe(0)
await pool.destroy()
pool = new DynamicThreadPool(
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.ROUND_ROBIN
- )?.nextWorkerId
- ).toBeUndefined()
+ ).nextWorkerNodeId
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.ROUND_ROBIN
- ).nextWorkerId
+ ).nextWorkerNodeId
).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.workerChoiceStrategies
+ for (const workerNodeKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.FAIR_SHARE)
.workerLastVirtualTaskTimestamp.keys()) {
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.FAIR_SHARE)
- .workerLastVirtualTaskTimestamp.get(workerKey).start
+ .workerLastVirtualTaskTimestamp.get(workerNodeKey).start
).toBe(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.FAIR_SHARE)
- .workerLastVirtualTaskTimestamp.get(workerKey).end
+ .workerLastVirtualTaskTimestamp.get(workerNodeKey).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()
})
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.FAIR_SHARE
).workerLastVirtualTaskTimestamp.size
- ).toBe(pool.workers.length)
+ ).toBe(pool.workerNodes.length)
// We need to clean up the resources after our test
await pool.destroy()
})
// pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
// WorkerChoiceStrategies.FAIR_SHARE
// ).workerLastVirtualTaskTimestamp.size
- // ).toBe(pool.workers.length)
+ // ).toBe(pool.workerNodes.length)
// }
// We need to clean up the resources after our test
await pool.destroy()
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.FAIR_SHARE
- )?.workerLastVirtualTaskTimestamp
- ).toBeUndefined()
+ ).workerLastVirtualTaskTimestamp
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
- for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ for (const workerNodeKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.FAIR_SHARE)
.workerLastVirtualTaskTimestamp.keys()) {
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.FAIR_SHARE)
- .workerLastVirtualTaskTimestamp.get(workerKey).start
+ .workerLastVirtualTaskTimestamp.get(workerNodeKey).start
).toBe(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.FAIR_SHARE)
- .workerLastVirtualTaskTimestamp.get(workerKey).end
+ .workerLastVirtualTaskTimestamp.get(workerNodeKey).end
).toBe(0)
}
await pool.destroy()
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.FAIR_SHARE
- )?.workerLastVirtualTaskTimestamp
- ).toBeUndefined()
+ ).workerLastVirtualTaskTimestamp
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
- for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ for (const workerNodeKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.FAIR_SHARE)
.workerLastVirtualTaskTimestamp.keys()) {
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.FAIR_SHARE)
- .workerLastVirtualTaskTimestamp.get(workerKey).start
+ .workerLastVirtualTaskTimestamp.get(workerNodeKey).start
).toBe(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.FAIR_SHARE)
- .workerLastVirtualTaskTimestamp.get(workerKey).end
+ .workerLastVirtualTaskTimestamp.get(workerNodeKey).end
).toBe(0)
}
// We need to clean up the resources after our test
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
- ).currentWorkerId
+ ).currentWorkerNodeId
).toBe(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
).defaultWorkerWeight
).toBeGreaterThan(0)
- for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ for (const workerNodeKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
.workersTaskRunTime.keys()) {
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
- .workersTaskRunTime.get(workerKey).weight
+ .workersTaskRunTime.get(workerNodeKey).weight
).toBeGreaterThan(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
- .workersTaskRunTime.get(workerKey).runTime
+ .workersTaskRunTime.get(workerNodeKey).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()
})
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
).workersTaskRunTime.size
- ).toBe(pool.workers.length)
+ ).toBe(pool.workerNodes.length)
// We need to clean up the resources after our test
await pool.destroy()
})
const maxMultiplier =
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
- ).defaultWorkerWeight * 2
+ ).defaultWorkerWeight * 50
for (let i = 0; i < max * maxMultiplier; i++) {
promises.push(pool.execute())
}
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
).workersTaskRunTime.size
- ).toBe(pool.workers.length)
+ ).toBe(pool.workerNodes.length)
}
// We need to clean up the resources after our test
await pool.destroy()
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
- )?.currentWorkerId
- ).toBeUndefined()
+ ).currentWorkerNodeId
+ ).toBeDefined()
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
- )?.defaultWorkerWeight
- ).toBeUndefined()
+ ).defaultWorkerWeight
+ ).toBeDefined()
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
- )?.workersTaskRunTime
- ).toBeUndefined()
+ ).workersTaskRunTime
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
- ).currentWorkerId
+ ).currentWorkerNodeId
).toBe(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
).defaultWorkerWeight
).toBeGreaterThan(0)
- for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ for (const workerNodeKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
.workersTaskRunTime.keys()) {
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
- .workersTaskRunTime.get(workerKey).runTime
+ .workersTaskRunTime.get(workerNodeKey).runTime
).toBe(0)
}
await pool.destroy()
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
- )?.currentWorkerId
- ).toBeUndefined()
+ ).currentWorkerNodeId
+ ).toBeDefined()
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
- )?.defaultWorkerWeight
- ).toBeUndefined()
+ ).defaultWorkerWeight
+ ).toBeDefined()
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
- )?.workersTaskRunTime
- ).toBeUndefined()
+ ).workersTaskRunTime
+ ).toBeDefined()
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
- ).currentWorkerId
+ ).currentWorkerNodeId
).toBe(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
).defaultWorkerWeight
).toBeGreaterThan(0)
- for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ for (const workerNodeKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
.workersTaskRunTime.keys()) {
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies
.get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
- .workersTaskRunTime.get(workerKey).runTime
+ .workersTaskRunTime.get(workerNodeKey).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'")
)
})
})