const { Queue } = require('../../../lib/queue')
describe('Abstract pool test suite', () => {
- const numberOfWorkers = 1
+ const numberOfWorkers = 2
class StubPoolWithRemoveAllWorker extends FixedThreadPool {
removeAllWorker () {
this.workerNodes = []
workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED,
workerChoiceStrategyOptions: {
medRunTime: true,
- weights: { 0: 300 }
+ weights: { 0: 300, 1: 200 }
},
enableEvents: false,
enableTasksQueue: true,
)
expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
medRunTime: true,
- weights: { 0: 300 }
+ weights: { 0: 300, 1: 200 }
})
expect(pool.opts.messageHandler).toStrictEqual(testHandler)
expect(pool.opts.errorHandler).toStrictEqual(testHandler)
'./tests/worker-files/cluster/testWorker.js'
)
const promises = []
- for (let i = 0; i < numberOfWorkers * 2; i++) {
+ const maxMultiplier = 2
+ for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) {
promises.push(pool.execute())
}
for (const workerNode of pool.workerNodes) {
expect(workerNode.tasksUsage).toStrictEqual({
run: 0,
- running: numberOfWorkers * 2,
+ running: maxMultiplier,
runTime: 0,
runTimeHistory: expect.any(CircularArray),
avgRunTime: 0,
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
expect(workerNode.tasksUsage).toStrictEqual({
- run: numberOfWorkers * 2,
+ run: maxMultiplier,
running: 0,
runTime: 0,
runTimeHistory: expect.any(CircularArray),
it('Verify that worker pool tasks usage are reset at worker choice strategy change', async () => {
const pool = new DynamicThreadPool(
numberOfWorkers,
- numberOfWorkers,
+ numberOfWorkers * 2,
'./tests/worker-files/thread/testWorker.js'
)
const promises = []
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
expect(workerNode.tasksUsage).toStrictEqual({
- run: numberOfWorkers * maxMultiplier,
+ run: expect.any(Number),
running: 0,
runTime: 0,
runTimeHistory: expect.any(CircularArray),
medWaitTime: 0,
error: 0
})
+ expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
+ expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(maxMultiplier)
}
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
for (const workerNode of pool.workerNodes) {
}
await Promise.all(promises)
// The `full` event is triggered when the number of submitted tasks at once reach the max number of workers in the dynamic pool.
- // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool.
- expect(poolFull).toBe(numberOfWorkers + 1)
+ // So in total numberOfWorkers * 2 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool with min = max = numberOfWorkers.
+ expect(poolFull).toBe(numberOfWorkers * 2)
await pool.destroy()
})
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
expect(workerNode.tasksUsage).toStrictEqual({
- run: expect.any(Number),
+ run: maxMultiplier,
running: 0,
runTime: 0,
runTimeHistory: expect.any(CircularArray),
medWaitTime: 0,
error: 0
})
- expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
- expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier)
}
// We need to clean up the resources after our test
await pool.destroy()
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
expect(workerNode.tasksUsage).toStrictEqual({
- run: expect.any(Number),
+ run: maxMultiplier,
running: 0,
runTime: 0,
runTimeHistory: expect.any(CircularArray),
medWaitTime: 0,
error: 0
})
- expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
- expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier)
}
// We need to clean up the resources after our test
await pool.destroy()
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
expect(workerNode.tasksUsage).toStrictEqual({
- run: expect.any(Number),
+ run: maxMultiplier,
running: 0,
runTime: 0,
runTimeHistory: expect.any(CircularArray),
medWaitTime: 0,
error: 0
})
- expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
- expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier)
}
// We need to clean up the resources after our test
await pool.destroy()
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
expect(workerNode.tasksUsage).toStrictEqual({
- run: expect.any(Number),
+ run: maxMultiplier,
running: 0,
runTime: 0,
runTimeHistory: expect.any(CircularArray),
medWaitTime: 0,
error: 0
})
- expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
- expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier)
}
// We need to clean up the resources after our test
await pool.destroy()
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
expect(workerNode.tasksUsage).toStrictEqual({
- run: expect.any(Number),
+ run: maxMultiplier,
running: 0,
runTime: expect.any(Number),
runTimeHistory: expect.any(CircularArray),
medWaitTime: 0,
error: 0
})
- expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
- expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier)
expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0)
expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThan(0)
}
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
expect(workerNode.tasksUsage).toStrictEqual({
- run: expect.any(Number),
+ run: maxMultiplier,
running: 0,
runTime: expect.any(Number),
runTimeHistory: expect.any(CircularArray),
medWaitTime: 0,
error: 0
})
- expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
- expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier)
expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0)
expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThan(0)
}
await Promise.all(promises)
for (const workerNode of pool.workerNodes) {
expect(workerNode.tasksUsage).toStrictEqual({
- run: expect.any(Number),
+ run: maxMultiplier,
running: 0,
runTime: expect.any(Number),
runTimeHistory: expect.any(CircularArray),
medWaitTime: 0,
error: 0
})
- expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
- expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier)
expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0)
expect(workerNode.tasksUsage.medRunTime).toBeGreaterThan(0)
}