From: Jérôme Benoit Date: Tue, 11 Oct 2022 22:02:00 +0000 (+0200) Subject: Test: Verify that worker pool tasks usage are reset at worker choice strategy change... X-Git-Tag: v2.3.1~20 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9e619829e79d59d19b11f19ddbb9efe51277da9d;p=poolifier.git Test: Verify that worker pool tasks usage are reset at worker choice strategy change, take2 Signed-off-by: Jérôme Benoit --- diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 0b33e36b..e1c83b6f 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -1,6 +1,7 @@ const { expect } = require('expect') const { FixedClusterPool, + DynamicThreadPool, FixedThreadPool, WorkerChoiceStrategies } = require('../../../lib/index') @@ -233,7 +234,7 @@ describe('Abstract pool test suite', () => { }) it('Verify that worker pool tasks usage are reset at worker choice strategy change', async () => { - const pool = new FixedThreadPool( + let pool = new FixedThreadPool( numberOfWorkers, './tests/worker-files/thread/testWorker.js' ) @@ -258,6 +259,32 @@ describe('Abstract pool test suite', () => { expect(tasksUsage.avgRunTime).toBe(0) } await pool.destroy() + pool = new DynamicThreadPool( + numberOfWorkers, + numberOfWorkers, + './tests/worker-files/thread/testWorker.js' + ) + promises.length = 0 + 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) + } + await pool.destroy() }) it("Verify that pool event emitter 'busy' event can register a callback", async () => {