From ee11a4a2effa596d1155bf8857b2920c9e62bae4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 11 Oct 2022 23:16:38 +0200 Subject: [PATCH] Tests: Verify that worker pool tasks usage are reset at worker choice strategy change MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- tests/pools/abstract/abstract-pool.test.js | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 96dc9a10..ac776174 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -232,6 +232,34 @@ describe('Abstract pool test suite', () => { pool.destroy() }) + it('Verify that worker pool tasks usage are reset at worker choice strategy change', async () => { + const pool = new FixedThreadPool( + numberOfWorkers, + './tests/worker-files/thread/testWorker.js' + ) + const promises = [] + for (let i = 0; i < numberOfWorkers * 2; i++) { + promises.push(pool.execute()) + } + await Promise.all(promises) + for (const tasksUsage of pool.workersTasksUsage.values()) { + expect(tasksUsage).toBeDefined() + expect(tasksUsage.run).toBe(numberOfWorkers * 2) + expect(tasksUsage.running).toBe(0) + expect(tasksUsage.runTime).toBeGreaterThanOrEqual(0) + expect(tasksUsage.avgRunTime).toBeGreaterThanOrEqual(0) + } + pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE) + for (const tasksUsage of pool.workersTasksUsage.values()) { + expect(tasksUsage).toBeDefined() + expect(tasksUsage.run).toBe(0) + expect(tasksUsage.running).toBe(0) + expect(tasksUsage.runTime).toBe(0) + expect(tasksUsage.avgRunTime).toBe(0) + } + pool.destroy() + }) + it("Verify that pool event emitter 'busy' event can register a callback", async () => { const pool = new FixedThreadPool( numberOfWorkers, -- 2.34.1