From 56d1167079ce8b4a043a8d750389f0d00ecccbad Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 25 Aug 2023 17:03:32 +0200 Subject: [PATCH] test: add task stealing support MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- tests/pools/cluster/fixed.test.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 900f0edc..85eb6a0a 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -4,7 +4,7 @@ const { TaskFunctions } = require('../../test-types') const { waitPoolEvents, waitWorkerEvents } = require('../../test-utils') describe('Fixed cluster pool test suite', () => { - const numberOfWorkers = 6 + const numberOfWorkers = 8 const tasksConcurrency = 2 const pool = new FixedClusterPool( numberOfWorkers, @@ -124,7 +124,9 @@ describe('Fixed cluster pool test suite', () => { 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( numberOfWorkers * queuePool.opts.tasksQueueOptions.concurrency ) @@ -137,6 +139,7 @@ describe('Fixed cluster pool test suite', () => { (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) @@ -148,7 +151,17 @@ describe('Fixed cluster pool test suite', () => { expect(workerNode.usage.tasks.maxQueued).toBe( maxMultiplier - queuePool.opts.tasksQueueOptions.concurrency ) + expect(workerNode.usage.tasks.stolen).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.stolen).toBeLessThanOrEqual( + numberOfWorkers * maxMultiplier + ) } + expect(queuePool.info.executedTasks).toBe(numberOfWorkers * maxMultiplier) + expect(queuePool.info.backPressure).toBe(false) + expect(queuePool.info.stolenTasks).toBeGreaterThanOrEqual(0) + expect(queuePool.info.stolenTasks).toBeLessThanOrEqual( + numberOfWorkers * maxMultiplier + ) }) it('Verify that is possible to have a worker that return undefined', async () => { -- 2.34.1