WorkerChoiceStrategies.ROUND_ROBIN
)
expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
- medRunTime: false
+ medRunTime: false,
+ medWaitTime: false
})
expect(pool.opts.messageHandler).toBeUndefined()
expect(pool.opts.errorHandler).toBeUndefined()
{ workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
)
expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
- medRunTime: false
+ medRunTime: false,
+ medWaitTime: false
})
for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
.workerChoiceStrategies) {
- expect(workerChoiceStrategy.opts).toStrictEqual({ medRunTime: false })
+ expect(workerChoiceStrategy.opts).toStrictEqual({
+ medRunTime: false,
+ medWaitTime: false
+ })
}
expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
- ).toBe(true)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
- ).toBe(false)
+ pool.workerChoiceStrategyContext.getRequiredStatistics()
+ ).toStrictEqual({
+ runTime: true,
+ avgRunTime: true,
+ medRunTime: false,
+ waitTime: false,
+ avgWaitTime: false,
+ medWaitTime: false
+ })
pool.setWorkerChoiceStrategyOptions({ medRunTime: true })
expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
medRunTime: true
expect(workerChoiceStrategy.opts).toStrictEqual({ medRunTime: true })
}
expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
- ).toBe(false)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
- ).toBe(true)
+ pool.workerChoiceStrategyContext.getRequiredStatistics()
+ ).toStrictEqual({
+ runTime: true,
+ avgRunTime: false,
+ medRunTime: true,
+ waitTime: false,
+ avgWaitTime: false,
+ medWaitTime: false
+ })
pool.setWorkerChoiceStrategyOptions({ medRunTime: false })
expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
medRunTime: false
expect(workerChoiceStrategy.opts).toStrictEqual({ medRunTime: false })
}
expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
- ).toBe(true)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
- ).toBe(false)
+ pool.workerChoiceStrategyContext.getRequiredStatistics()
+ ).toStrictEqual({
+ runTime: true,
+ avgRunTime: true,
+ medRunTime: false,
+ waitTime: false,
+ avgWaitTime: false,
+ medWaitTime: false
+ })
await pool.destroy()
})
'./tests/worker-files/cluster/testWorker.js'
)
for (const workerNode of pool.workerNodes) {
- expect(workerNode.tasksUsage).toBeDefined()
- expect(workerNode.tasksUsage.run).toBe(0)
- expect(workerNode.tasksUsage.running).toBe(0)
- expect(workerNode.tasksUsage.runTime).toBe(0)
- expect(workerNode.tasksUsage.runTimeHistory).toBeInstanceOf(CircularArray)
- expect(workerNode.tasksUsage.runTimeHistory.length).toBe(0)
- expect(workerNode.tasksUsage.avgRunTime).toBe(0)
- expect(workerNode.tasksUsage.medRunTime).toBe(0)
- expect(workerNode.tasksUsage.error).toBe(0)
+ expect(workerNode.tasksUsage).toStrictEqual({
+ run: 0,
+ running: 0,
+ runTime: 0,
+ runTimeHistory: expect.any(CircularArray),
+ avgRunTime: 0,
+ medRunTime: 0,
+ waitTime: 0,
+ waitTimeHistory: expect.any(CircularArray),
+ avgWaitTime: 0,
+ medWaitTime: 0,
+ error: 0
+ })
}
await pool.destroy()
})
promises.push(pool.execute())
}
for (const workerNode of pool.workerNodes) {
- expect(workerNode.tasksUsage).toBeDefined()
- expect(workerNode.tasksUsage.run).toBe(0)
- expect(workerNode.tasksUsage.running).toBe(numberOfWorkers * 2)
- expect(workerNode.tasksUsage.runTime).toBe(0)
- expect(workerNode.tasksUsage.runTimeHistory).toBeInstanceOf(CircularArray)
- expect(workerNode.tasksUsage.runTimeHistory.length).toBe(0)
- expect(workerNode.tasksUsage.avgRunTime).toBe(0)
- expect(workerNode.tasksUsage.medRunTime).toBe(0)
- expect(workerNode.tasksUsage.error).toBe(0)
+ expect(workerNode.tasksUsage).toStrictEqual({
+ run: 0,
+ running: numberOfWorkers * 2,
+ runTime: 0,
+ runTimeHistory: expect.any(CircularArray),
+ avgRunTime: 0,
+ medRunTime: 0,
+ waitTime: 0,
+ waitTimeHistory: expect.any(CircularArray),
+ avgWaitTime: 0,
+ medWaitTime: 0,
+ error: 0
+ })
}
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
- expect(workerNode.tasksUsage).toBeDefined()
- expect(workerNode.tasksUsage.run).toBe(numberOfWorkers * 2)
- expect(workerNode.tasksUsage.running).toBe(0)
- expect(workerNode.tasksUsage.runTime).toBeGreaterThanOrEqual(0)
- expect(workerNode.tasksUsage.runTimeHistory).toBeInstanceOf(CircularArray)
- expect(workerNode.tasksUsage.runTimeHistory.length).toBe(0)
- expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThanOrEqual(0)
- expect(workerNode.tasksUsage.medRunTime).toBe(0)
- expect(workerNode.tasksUsage.error).toBe(0)
+ expect(workerNode.tasksUsage).toStrictEqual({
+ run: numberOfWorkers * 2,
+ running: 0,
+ runTime: 0,
+ runTimeHistory: expect.any(CircularArray),
+ avgRunTime: 0,
+ medRunTime: 0,
+ waitTime: 0,
+ waitTimeHistory: expect.any(CircularArray),
+ avgWaitTime: 0,
+ medWaitTime: 0,
+ error: 0
+ })
}
await pool.destroy()
})
}
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
- expect(workerNode.tasksUsage).toBeDefined()
- expect(workerNode.tasksUsage.run).toBe(numberOfWorkers * 2)
- expect(workerNode.tasksUsage.running).toBe(0)
+ expect(workerNode.tasksUsage).toStrictEqual({
+ run: numberOfWorkers * 2,
+ running: 0,
+ runTime: expect.any(Number),
+ runTimeHistory: expect.any(CircularArray),
+ avgRunTime: 0,
+ medRunTime: 0,
+ waitTime: 0,
+ waitTimeHistory: expect.any(CircularArray),
+ avgWaitTime: 0,
+ medWaitTime: 0,
+ error: 0
+ })
expect(workerNode.tasksUsage.runTime).toBeGreaterThanOrEqual(0)
- expect(workerNode.tasksUsage.runTimeHistory).toBeInstanceOf(CircularArray)
- expect(workerNode.tasksUsage.runTimeHistory.length).toBe(0)
expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThanOrEqual(0)
- expect(workerNode.tasksUsage.medRunTime).toBe(0)
- expect(workerNode.tasksUsage.error).toBe(0)
}
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
for (const workerNode of pool.workerNodes) {
expect(workerNode.tasksUsage).toBeDefined()
- expect(workerNode.tasksUsage.run).toBe(0)
- expect(workerNode.tasksUsage.running).toBe(0)
- expect(workerNode.tasksUsage.runTime).toBe(0)
- expect(workerNode.tasksUsage.runTimeHistory).toBeInstanceOf(CircularArray)
+ expect(workerNode.tasksUsage).toStrictEqual({
+ run: 0,
+ running: 0,
+ runTime: 0,
+ runTimeHistory: expect.any(CircularArray),
+ avgRunTime: 0,
+ medRunTime: 0,
+ waitTime: 0,
+ waitTimeHistory: expect.any(CircularArray),
+ avgWaitTime: 0,
+ medWaitTime: 0,
+ error: 0
+ })
expect(workerNode.tasksUsage.runTimeHistory.length).toBe(0)
- expect(workerNode.tasksUsage.avgRunTime).toBe(0)
- expect(workerNode.tasksUsage.medRunTime).toBe(0)
- expect(workerNode.tasksUsage.error).toBe(0)
}
await pool.destroy()
})
FixedThreadPool,
FixedClusterPool
} = require('../../../lib')
+const { CircularArray } = require('../../../lib/circular-array')
describe('Selection strategies test suite', () => {
const min = 0
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
- ).toBe(false)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
- ).toBe(false)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
- ).toBe(false)
+ pool.workerChoiceStrategyContext.getRequiredStatistics()
+ ).toStrictEqual({
+ runTime: false,
+ avgRunTime: false,
+ medRunTime: false,
+ waitTime: false,
+ avgWaitTime: false,
+ medWaitTime: false
+ })
await pool.destroy()
pool = new DynamicThreadPool(
min,
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
- ).toBe(false)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
- ).toBe(false)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
- ).toBe(false)
+ pool.workerChoiceStrategyContext.getRequiredStatistics()
+ ).toStrictEqual({
+ runTime: false,
+ avgRunTime: false,
+ medRunTime: false,
+ waitTime: false,
+ avgWaitTime: false,
+ medWaitTime: false
+ })
// We need to clean up the resources after our test
await pool.destroy()
})
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
- ).toBe(false)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
- ).toBe(false)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
- ).toBe(false)
+ pool.workerChoiceStrategyContext.getRequiredStatistics()
+ ).toStrictEqual({
+ runTime: false,
+ avgRunTime: false,
+ medRunTime: false,
+ waitTime: false,
+ avgWaitTime: false,
+ medWaitTime: false
+ })
await pool.destroy()
pool = new DynamicThreadPool(
min,
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
- ).toBe(false)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
- ).toBe(false)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
- ).toBe(false)
+ pool.workerChoiceStrategyContext.getRequiredStatistics()
+ ).toStrictEqual({
+ runTime: false,
+ avgRunTime: false,
+ medRunTime: false,
+ waitTime: false,
+ avgWaitTime: false,
+ medWaitTime: false
+ })
// We need to clean up the resources after our test
await pool.destroy()
})
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
- ).toBe(true)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
- ).toBe(false)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
- ).toBe(false)
+ pool.workerChoiceStrategyContext.getRequiredStatistics()
+ ).toStrictEqual({
+ runTime: true,
+ avgRunTime: false,
+ medRunTime: false,
+ waitTime: false,
+ avgWaitTime: false,
+ medWaitTime: false
+ })
await pool.destroy()
pool = new DynamicThreadPool(
min,
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
- ).toBe(true)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
- ).toBe(false)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
- ).toBe(false)
+ pool.workerChoiceStrategyContext.getRequiredStatistics()
+ ).toStrictEqual({
+ runTime: true,
+ avgRunTime: false,
+ medRunTime: false,
+ waitTime: false,
+ avgWaitTime: false,
+ medWaitTime: false
+ })
// We need to clean up the resources after our test
await pool.destroy()
})
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
- ).toBe(true)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
- ).toBe(true)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
- ).toBe(false)
+ pool.workerChoiceStrategyContext.getRequiredStatistics()
+ ).toStrictEqual({
+ runTime: true,
+ avgRunTime: true,
+ medRunTime: false,
+ waitTime: false,
+ avgWaitTime: false,
+ medWaitTime: false
+ })
await pool.destroy()
pool = new DynamicThreadPool(
min,
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
- ).toBe(true)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
- ).toBe(true)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
- ).toBe(false)
+ pool.workerChoiceStrategyContext.getRequiredStatistics()
+ ).toStrictEqual({
+ runTime: true,
+ avgRunTime: true,
+ medRunTime: false,
+ waitTime: false,
+ avgWaitTime: false,
+ medWaitTime: false
+ })
// We need to clean up the resources after our test
await pool.destroy()
})
await pool.execute()
}
for (const workerNode of pool.workerNodes) {
- expect(workerNode.tasksUsage.avgRunTime).toBeDefined()
+ expect(workerNode.tasksUsage).toStrictEqual({
+ run: maxMultiplier,
+ running: 0,
+ runTime: expect.any(Number),
+ runTimeHistory: expect.any(CircularArray),
+ avgRunTime: expect.any(Number),
+ medRunTime: 0,
+ waitTime: 0,
+ waitTimeHistory: expect.any(CircularArray),
+ avgWaitTime: 0,
+ medWaitTime: 0,
+ error: 0
+ })
expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThanOrEqual(0)
- expect(workerNode.tasksUsage.medRunTime).toBeDefined()
- expect(workerNode.tasksUsage.medRunTime).toBe(0)
}
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
await pool.execute()
}
for (const workerNode of pool.workerNodes) {
- expect(workerNode.tasksUsage.avgRunTime).toBeDefined()
+ expect(workerNode.tasksUsage).toStrictEqual({
+ run: max * maxMultiplier,
+ running: 0,
+ runTime: expect.any(Number),
+ runTimeHistory: expect.any(CircularArray),
+ avgRunTime: expect.any(Number),
+ medRunTime: 0,
+ waitTime: 0,
+ waitTimeHistory: expect.any(CircularArray),
+ avgWaitTime: 0,
+ medWaitTime: 0,
+ error: 0
+ })
expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThanOrEqual(0)
- expect(workerNode.tasksUsage.medRunTime).toBeDefined()
- expect(workerNode.tasksUsage.medRunTime).toBe(0)
}
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
await pool.execute()
}
for (const workerNode of pool.workerNodes) {
- expect(workerNode.tasksUsage.avgRunTime).toBeDefined()
- expect(workerNode.tasksUsage.avgRunTime).toBe(0)
- expect(workerNode.tasksUsage.medRunTime).toBeDefined()
+ expect(workerNode.tasksUsage).toStrictEqual({
+ run: max * maxMultiplier,
+ running: 0,
+ runTime: expect.any(Number),
+ runTimeHistory: expect.any(CircularArray),
+ avgRunTime: 0,
+ medRunTime: expect.any(Number),
+ waitTime: 0,
+ waitTimeHistory: expect.any(CircularArray),
+ avgWaitTime: 0,
+ medWaitTime: 0,
+ error: 0
+ })
expect(workerNode.tasksUsage.medRunTime).toBeGreaterThanOrEqual(0)
}
expect(
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
- ).toBe(true)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
- ).toBe(true)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
- ).toBe(false)
+ pool.workerChoiceStrategyContext.getRequiredStatistics()
+ ).toStrictEqual({
+ runTime: true,
+ avgRunTime: true,
+ medRunTime: false,
+ waitTime: false,
+ avgWaitTime: false,
+ medWaitTime: false
+ })
await pool.destroy()
pool = new DynamicThreadPool(
min,
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
- ).toBe(true)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
- ).toBe(true)
- expect(
- pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
- ).toBe(false)
+ pool.workerChoiceStrategyContext.getRequiredStatistics()
+ ).toStrictEqual({
+ runTime: true,
+ avgRunTime: true,
+ medRunTime: false,
+ waitTime: false,
+ avgWaitTime: false,
+ medWaitTime: false
+ })
// We need to clean up the resources after our test
await pool.destroy()
})
await pool.execute()
}
for (const workerNode of pool.workerNodes) {
- expect(workerNode.tasksUsage.avgRunTime).toBeDefined()
+ expect(workerNode.tasksUsage).toStrictEqual({
+ run: max * maxMultiplier,
+ running: 0,
+ runTime: expect.any(Number),
+ runTimeHistory: expect.any(CircularArray),
+ avgRunTime: expect.any(Number),
+ medRunTime: 0,
+ waitTime: 0,
+ waitTimeHistory: expect.any(CircularArray),
+ avgWaitTime: 0,
+ medWaitTime: 0,
+ error: 0
+ })
expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThanOrEqual(0)
- expect(workerNode.tasksUsage.medRunTime).toBeDefined()
- expect(workerNode.tasksUsage.medRunTime).toBe(0)
}
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
await pool.execute()
}
for (const workerNode of pool.workerNodes) {
- expect(workerNode.tasksUsage.avgRunTime).toBeDefined()
+ expect(workerNode.tasksUsage).toStrictEqual({
+ run: max * maxMultiplier,
+ running: 0,
+ runTime: expect.any(Number),
+ runTimeHistory: expect.any(CircularArray),
+ avgRunTime: expect.any(Number),
+ medRunTime: 0,
+ waitTime: 0,
+ waitTimeHistory: expect.any(CircularArray),
+ avgWaitTime: 0,
+ medWaitTime: 0,
+ error: 0
+ })
expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThanOrEqual(0)
- expect(workerNode.tasksUsage.medRunTime).toBeDefined()
- expect(workerNode.tasksUsage.medRunTime).toBe(0)
}
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
await pool.execute()
}
for (const workerNode of pool.workerNodes) {
- expect(workerNode.tasksUsage.avgRunTime).toBeDefined()
- expect(workerNode.tasksUsage.avgRunTime).toBe(0)
- expect(workerNode.tasksUsage.medRunTime).toBeDefined()
+ expect(workerNode.tasksUsage).toStrictEqual({
+ run: max * maxMultiplier,
+ running: 0,
+ runTime: expect.any(Number),
+ runTimeHistory: expect.any(CircularArray),
+ avgRunTime: 0,
+ medRunTime: expect.any(Number),
+ waitTime: 0,
+ waitTimeHistory: expect.any(CircularArray),
+ avgWaitTime: 0,
+ medWaitTime: 0,
+ error: 0
+ })
expect(workerNode.tasksUsage.medRunTime).toBeGreaterThanOrEqual(0)
}
expect(