}
private async startOnEmptyQueue (): Promise<void> {
- if (this.tasksQueue.size > 0) {
+ if (
+ this.onEmptyQueueCount > 0 &&
+ this.usage.tasks.executing > 0 &&
+ this.tasksQueue.size > 0
+ ) {
this.onEmptyQueueCount = 0
return
}
expect(workerNode.usage.tasks.maxQueued).toBe(
maxMultiplier - queuePool.opts.tasksQueueOptions.concurrency
)
+ expect(workerNode.usage.tasks.stolen).toBe(0)
}
+ expect(queuePool.info.executedTasks).toBe(0)
expect(queuePool.info.executingTasks).toBe(
numberOfThreads * queuePool.opts.tasksQueueOptions.concurrency
)
(maxMultiplier - queuePool.opts.tasksQueueOptions.concurrency)
)
expect(queuePool.info.backPressure).toBe(false)
+ expect(queuePool.info.stolenTasks).toBe(0)
await Promise.all(promises)
for (const workerNode of queuePool.workerNodes) {
expect(workerNode.usage.tasks.executing).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.maxQueued).toBe(
maxMultiplier - queuePool.opts.tasksQueueOptions.concurrency
)
+ expect(workerNode.usage.tasks.stolen).toBeGreaterThanOrEqual(0)
+ expect(workerNode.usage.tasks.stolen).toBeLessThanOrEqual(
+ numberOfThreads * maxMultiplier
+ )
}
+ expect(queuePool.info.executedTasks).toBe(numberOfThreads * maxMultiplier)
+ expect(queuePool.info.backPressure).toBe(false)
+ expect(queuePool.info.stolenTasks).toBeGreaterThanOrEqual(0)
+ expect(queuePool.info.stolenTasks).toBeLessThanOrEqual(
+ numberOfThreads * maxMultiplier
+ )
})
it('Verify that is possible to have a worker that return undefined', async () => {
})
it('Verify exponentialDelay() behavior', () => {
- expect(typeof exponentialDelay(randomInt(1000)) === 'number').toBe(true)
- expect(exponentialDelay(randomInt(1000))).toBeGreaterThanOrEqual(
- Number.MIN_VALUE
- )
- expect(exponentialDelay(randomInt(1000))).toBeLessThanOrEqual(
- Number.MAX_VALUE
- )
+ const delay = exponentialDelay(randomInt(1000))
+ expect(typeof delay === 'number').toBe(true)
+ expect(delay).toBeGreaterThanOrEqual(Number.MIN_VALUE)
+ expect(delay).toBeLessThanOrEqual(Number.MAX_VALUE)
})
it('Verify average() computation', () => {