From: Jérôme Benoit Date: Fri, 14 Apr 2023 16:40:57 +0000 (+0200) Subject: test: enhance tasks queueing tests X-Git-Tag: v2.4.9~24 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=d3d4b67d8301265da89328a0a05ab68438add3ed;p=poolifier.git test: enhance tasks queueing tests Signed-off-by: Jérôme Benoit --- diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index ddcca105..c28b8021 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -90,9 +90,11 @@ describe('Fixed cluster pool test suite', () => { it('Verify that tasks queuing is working', async () => { const maxMultiplier = 10 + const promises = new Set() for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) { - queuePool.execute() + promises.add(queuePool.execute()) } + expect(promises.size).toBe(numberOfWorkers * maxMultiplier) for (const workerNode of queuePool.workerNodes) { expect(workerNode.tasksUsage.running).toBeLessThanOrEqual( queuePool.opts.tasksQueueOptions.concurrency @@ -100,17 +102,17 @@ describe('Fixed cluster pool test suite', () => { expect(workerNode.tasksUsage.run).toBe(0) expect(workerNode.tasksQueue.length).toBeGreaterThan(0) } - // FIXME: wait for ongoing tasks to be executed - const promises = [] - for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) { - promises.push(queuePool.execute()) - } + expect(queuePool.numberOfRunningTasks).toBe(numberOfWorkers) + expect(queuePool.numberOfQueuedTasks).toBe( + numberOfWorkers * maxMultiplier - numberOfWorkers + ) await Promise.all(promises) for (const workerNode of queuePool.workerNodes) { expect(workerNode.tasksUsage.running).toBe(0) expect(workerNode.tasksUsage.run).toBeGreaterThan(0) expect(workerNode.tasksQueue.length).toBe(0) } + promises.clear() }) it('Verify that is possible to have a worker that return undefined', async () => { diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index 7b4b9bf5..75c4a935 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -90,9 +90,11 @@ describe('Fixed thread pool test suite', () => { it('Verify that tasks queuing is working', async () => { const maxMultiplier = 10 + const promises = new Set() for (let i = 0; i < numberOfThreads * maxMultiplier; i++) { - queuePool.execute() + promises.add(queuePool.execute()) } + expect(promises.size).toBe(numberOfThreads * maxMultiplier) for (const workerNode of queuePool.workerNodes) { expect(workerNode.tasksUsage.running).toBeLessThanOrEqual( queuePool.opts.tasksQueueOptions.concurrency @@ -100,17 +102,17 @@ describe('Fixed thread pool test suite', () => { expect(workerNode.tasksUsage.run).toBe(0) expect(workerNode.tasksQueue.length).toBeGreaterThan(0) } - // FIXME: wait for ongoing tasks to be executed - const promises = [] - for (let i = 0; i < numberOfThreads * maxMultiplier; i++) { - promises.push(queuePool.execute()) - } + expect(queuePool.numberOfRunningTasks).toBe(numberOfThreads) + expect(queuePool.numberOfQueuedTasks).toBe( + numberOfThreads * maxMultiplier - numberOfThreads + ) await Promise.all(promises) for (const workerNode of queuePool.workerNodes) { expect(workerNode.tasksUsage.running).toBe(0) expect(workerNode.tasksUsage.run).toBeGreaterThan(0) expect(workerNode.tasksQueue.length).toBe(0) } + promises.clear() }) it('Verify that is possible to have a worker that return undefined', async () => {