const { expect } = require('expect')
const {
+ DynamicClusterPool,
DynamicThreadPool,
FixedClusterPool,
FixedThreadPool,
expect(pool.workerChoiceStrategyContext.workerChoiceStrategy).toBe(
workerChoiceStrategy
)
+ expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
+ retries: 6,
+ runTime: { median: false },
+ waitTime: { median: false },
+ elu: { median: false }
+ })
+ expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
+ retries: 6,
+ runTime: { median: false },
+ waitTime: { median: false },
+ elu: { median: false }
+ })
+ await pool.destroy()
+ }
+ for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
+ const pool = new DynamicClusterPool(
+ min,
+ max,
+ './tests/worker-files/cluster/testWorker.js'
+ )
+ pool.setWorkerChoiceStrategy(workerChoiceStrategy, { retries: 3 })
+ expect(pool.opts.workerChoiceStrategy).toBe(workerChoiceStrategy)
+ expect(pool.workerChoiceStrategyContext.workerChoiceStrategy).toBe(
+ workerChoiceStrategy
+ )
+ expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
+ retries: 3,
+ runTime: { median: false },
+ waitTime: { median: false },
+ elu: { median: false }
+ })
+ expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
+ retries: 3,
+ runTime: { median: false },
+ waitTime: { median: false },
+ elu: { median: false }
+ })
await pool.destroy()
}
})
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
runTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
waitTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
active: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
}
}
})
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
runTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
waitTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
active: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
}
}
})
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
runTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
waitTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
active: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
}
}
})
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
runTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
waitTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
active: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
}
}
})
}
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
- expect(workerNode.usage).toMatchObject({
+ expect(workerNode.usage).toStrictEqual({
tasks: {
executed: expect.any(Number),
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
- runTime: {
+ runTime: expect.objectContaining({
history: expect.any(CircularArray)
- },
- waitTime: {
+ }),
+ waitTime: expect.objectContaining({
history: expect.any(CircularArray)
- },
+ }),
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
active: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
}
}
})
}
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
- expect(workerNode.usage).toMatchObject({
+ expect(workerNode.usage).toStrictEqual({
tasks: {
executed: expect.any(Number),
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
- runTime: {
+ runTime: expect.objectContaining({
history: expect.any(CircularArray)
- },
- waitTime: {
+ }),
+ waitTime: expect.objectContaining({
history: expect.any(CircularArray)
- },
+ }),
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
active: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
}
}
})
}
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
- expect(workerNode.usage).toMatchObject({
+ expect(workerNode.usage).toStrictEqual({
tasks: {
executed: expect.any(Number),
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
runTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
waitTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
- elu: {
+ elu: expect.objectContaining({
idle: expect.objectContaining({
history: expect.any(CircularArray)
}),
active: expect.objectContaining({
history: expect.any(CircularArray)
})
- }
+ })
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
max * maxMultiplier
)
+ if (workerNode.usage.elu.active.aggregate == null) {
+ expect(workerNode.usage.elu.active.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.elu.active.aggregate).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.elu.idle.aggregate == null) {
+ expect(workerNode.usage.elu.idle.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.elu.idle.aggregate).toBeGreaterThanOrEqual(0)
+ }
if (workerNode.usage.elu.utilization == null) {
expect(workerNode.usage.elu.utilization).toBeUndefined()
} else {
}
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
- expect(workerNode.usage).toMatchObject({
+ expect(workerNode.usage).toStrictEqual({
tasks: {
executed: expect.any(Number),
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
runTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
waitTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
- elu: {
+ elu: expect.objectContaining({
idle: expect.objectContaining({
history: expect.any(CircularArray)
}),
active: expect.objectContaining({
history: expect.any(CircularArray)
})
- }
+ })
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
max * maxMultiplier
)
+ if (workerNode.usage.elu.active.aggregate == null) {
+ expect(workerNode.usage.elu.active.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.elu.active.aggregate).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.elu.idle.aggregate == null) {
+ expect(workerNode.usage.elu.idle.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.elu.idle.aggregate).toBeGreaterThanOrEqual(0)
+ }
if (workerNode.usage.elu.utilization == null) {
expect(workerNode.usage.elu.utilization).toBeUndefined()
} else {
}
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
- expect(workerNode.usage).toMatchObject({
+ expect(workerNode.usage).toStrictEqual({
tasks: {
executed: expect.any(Number),
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
runTime: expect.objectContaining({
history: expect.any(CircularArray)
}),
waitTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
- elu: {
+ elu: expect.objectContaining({
idle: expect.objectContaining({
history: expect.any(CircularArray)
}),
active: expect.objectContaining({
history: expect.any(CircularArray)
})
- }
+ })
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
} else {
expect(workerNode.usage.runTime.average).toBeGreaterThan(0)
}
+ if (workerNode.usage.elu.active.aggregate == null) {
+ expect(workerNode.usage.elu.active.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.elu.active.aggregate).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.elu.idle.aggregate == null) {
+ expect(workerNode.usage.elu.idle.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.elu.idle.aggregate).toBeGreaterThanOrEqual(0)
+ }
if (workerNode.usage.elu.utilization == null) {
expect(workerNode.usage.elu.utilization).toBeUndefined()
} else {
}
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
- expect(workerNode.usage).toMatchObject({
+ expect(workerNode.usage).toStrictEqual({
tasks: {
executed: expect.any(Number),
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
runTime: expect.objectContaining({
history: expect.any(CircularArray)
}),
waitTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
- elu: {
+ elu: expect.objectContaining({
idle: expect.objectContaining({
history: expect.any(CircularArray)
}),
active: expect.objectContaining({
history: expect.any(CircularArray)
})
- }
+ })
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
} else {
expect(workerNode.usage.runTime.average).toBeGreaterThan(0)
}
+ if (workerNode.usage.elu.active.aggregate == null) {
+ expect(workerNode.usage.elu.active.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.elu.active.aggregate).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.elu.idle.aggregate == null) {
+ expect(workerNode.usage.elu.idle.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.elu.idle.aggregate).toBeGreaterThanOrEqual(0)
+ }
if (workerNode.usage.elu.utilization == null) {
expect(workerNode.usage.elu.utilization).toBeUndefined()
} else {
}
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
- expect(workerNode.usage).toMatchObject({
+ expect(workerNode.usage).toStrictEqual({
tasks: {
executed: expect.any(Number),
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
runTime: expect.objectContaining({
history: expect.any(CircularArray)
}),
waitTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
- elu: {
+ elu: expect.objectContaining({
idle: expect.objectContaining({
history: expect.any(CircularArray)
}),
active: expect.objectContaining({
history: expect.any(CircularArray)
})
- }
+ })
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
} else {
expect(workerNode.usage.runTime.median).toBeGreaterThan(0)
}
+ if (workerNode.usage.elu.active.aggregate == null) {
+ expect(workerNode.usage.elu.active.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.elu.active.aggregate).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.elu.idle.aggregate == null) {
+ expect(workerNode.usage.elu.idle.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.elu.idle.aggregate).toBeGreaterThanOrEqual(0)
+ }
if (workerNode.usage.elu.utilization == null) {
expect(workerNode.usage.elu.utilization).toBeUndefined()
} else {
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
runTime: expect.objectContaining({
history: expect.any(CircularArray)
}),
waitTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
active: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
}
}
})
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
runTime: expect.objectContaining({
history: expect.any(CircularArray)
}),
waitTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
active: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
}
}
})
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
runTime: expect.objectContaining({
history: expect.any(CircularArray)
}),
waitTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
active: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
}
}
})
pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
- aggregate: false,
- average: false,
+ aggregate: true,
+ average: true,
median: false
},
waitTime: {
pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
- aggregate: false,
- average: false,
+ aggregate: true,
+ average: true,
median: false
},
waitTime: {
for (const workerNode of pool.workerNodes) {
expect(workerNode.usage).toStrictEqual({
tasks: {
- executed: maxMultiplier,
+ executed: expect.any(Number),
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
- runTime: {
+ runTime: expect.objectContaining({
history: expect.any(CircularArray)
- },
+ }),
waitTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
active: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
}
}
})
+ expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
+ expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
+ max * maxMultiplier
+ )
}
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
).roundId
).toBe(0)
+ expect(
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategyContext.workerChoiceStrategy
+ ).workerNodeId
+ ).toBe(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
executing: 0,
queued: 0,
maxQueued: 0,
+ stolen: 0,
failed: 0
},
- runTime: {
+ runTime: expect.objectContaining({
history: expect.any(CircularArray)
- },
+ }),
waitTime: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
},
active: {
- history: expect.any(CircularArray)
+ history: new CircularArray()
}
}
})
pool.workerChoiceStrategyContext.workerChoiceStrategy
).roundId
).toBe(0)
+ expect(
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategyContext.workerChoiceStrategy
+ ).workerNodeId
+ ).toBe(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy