expect(pool.workerChoiceStrategyContext.workerChoiceStrategy).toBe(
workerChoiceStrategy
)
- expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
- retries: 6,
- runTime: { median: false },
- waitTime: { median: false },
- elu: { median: false }
- })
+ expect(pool.opts.workerChoiceStrategyOptions).toBeUndefined()
expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
- retries: 6,
+ retries:
+ pool.info.maxSize +
+ Object.keys(pool.workerChoiceStrategyContext.opts.weights).length,
runTime: { median: false },
waitTime: { median: false },
- elu: { median: false }
+ elu: { median: false },
+ weights: expect.objectContaining({
+ 0: expect.any(Number),
+ [pool.info.maxSize - 1]: expect.any(Number)
+ })
})
await pool.destroy()
}
max,
'./tests/worker-files/cluster/testWorker.js'
)
- pool.setWorkerChoiceStrategy(workerChoiceStrategy, { retries: 3 })
+ pool.setWorkerChoiceStrategy(workerChoiceStrategy)
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.opts.workerChoiceStrategyOptions).toBeUndefined()
expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
- retries: 3,
+ retries:
+ pool.info.maxSize +
+ Object.keys(pool.workerChoiceStrategyContext.opts.weights).length,
runTime: { median: false },
waitTime: { median: false },
- elu: { median: false }
+ elu: { median: false },
+ weights: expect.objectContaining({
+ 0: expect.any(Number),
+ [pool.info.maxSize - 1]: expect.any(Number)
+ })
})
await pool.destroy()
}
if (
workerChoiceStrategy === WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
) {
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
workerChoiceStrategy
workerChoiceStrategy ===
WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
) {
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
workerChoiceStrategy
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
workerChoiceStrategy
- ).roundWeights
- ).toStrictEqual([
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).defaultWorkerWeight
- ])
+ ).roundWeights.length
+ ).toBe(1)
+ expect(
+ Number.isSafeInteger(
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).roundWeights[0]
+ )
+ ).toBe(true)
}
}
await pool.destroy()
})
+ it('Verify strategies wait for worker node readiness in dynamic pool', async () => {
+ const pool = new DynamicThreadPool(
+ min,
+ max,
+ './tests/worker-files/thread/testWorker.mjs'
+ )
+ expect(pool.starting).toBe(false)
+ expect(pool.workerNodes.length).toBe(min)
+ const maxMultiplier = 10000
+ const promises = new Set()
+ for (let i = 0; i < max * maxMultiplier; i++) {
+ promises.add(pool.execute())
+ }
+ await Promise.all(promises)
+ expect(pool.workerNodes.length).toBe(max)
+ // We need to clean up the resources after our test
+ await pool.destroy()
+ })
+
it('Verify ROUND_ROBIN strategy default policy', async () => {
const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
let pool = new FixedThreadPool(
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
).previousWorkerNodeKey
- ).toBe(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
+ ).toEqual(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
).nextWorkerNodeKey
- ).toBe(0)
+ ).toEqual(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
).previousWorkerNodeKey
- ).toBe(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
+ ).toEqual(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
).nextWorkerNodeKey
- ).toBe(0)
+ ).toEqual(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
).previousWorkerNodeKey
- ).toBe(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
+ ).toEqual(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
workerChoiceStrategy
).previousWorkerNodeKey
).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeDefined()
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
workerChoiceStrategy
pool.workerChoiceStrategyContext.workerChoiceStrategy
).previousWorkerNodeKey
).toBe(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
workerChoiceStrategy
).previousWorkerNodeKey
).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeDefined()
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
workerChoiceStrategy
pool.workerChoiceStrategyContext.workerChoiceStrategy
).previousWorkerNodeKey
).toBe(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
max * maxMultiplier
)
}
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
).previousWorkerNodeKey
- ).toEqual(expect.any(Number))
+ ).toEqual(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).roundWeights
- ).toStrictEqual([
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ])
+ ).roundWeights.length
+ ).toBe(1)
+ expect(
+ Number.isSafeInteger(
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategyContext.workerChoiceStrategy
+ ).roundWeights[0]
+ )
+ ).toBe(true)
// We need to clean up the resources after our test
await pool.destroy()
})
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
failed: 0
},
max * maxMultiplier
)
}
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
).previousWorkerNodeKey
- ).toEqual(expect.any(Number))
+ ).toEqual(0)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).roundWeights
- ).toStrictEqual([
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ])
+ ).roundWeights.length
+ ).toBe(1)
+ expect(
+ Number.isSafeInteger(
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategyContext.workerChoiceStrategy
+ ).roundWeights[0]
+ )
+ ).toBe(true)
// We need to clean up the resources after our test
await pool.destroy()
})
workerChoiceStrategy
).previousWorkerNodeKey
).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeDefined()
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
workerChoiceStrategy
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
+ ).roundWeights.length
+ ).toBe(1)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).roundWeights
- ).toStrictEqual([
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ])
+ Number.isSafeInteger(
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategyContext.workerChoiceStrategy
+ ).roundWeights[0]
+ )
+ ).toBe(true)
await pool.destroy()
pool = new DynamicThreadPool(
min,
workerChoiceStrategy
).previousWorkerNodeKey
).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeDefined()
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
workerChoiceStrategy
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
+ ).roundWeights.length
+ ).toBe(1)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).roundWeights
- ).toStrictEqual([
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ])
+ Number.isSafeInteger(
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategyContext.workerChoiceStrategy
+ ).roundWeights[0]
+ )
+ ).toBe(true)
// We need to clean up the resources after our test
await pool.destroy()
})