From f0829c537c1be61af8472ce3167d7a58fe0c8e69 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 12 Oct 2022 19:11:38 +0200 Subject: [PATCH] Tests: also test strategy statistics reset on dynamic pool MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../selection-strategies.test.js | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index ce1b4313..7b11bf40 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -278,7 +278,7 @@ describe('Selection strategies test suite', () => { }) it('Verify FAIR_SHARE strategy statistics are resets after setting it', async () => { - const pool = new FixedThreadPool( + let pool = new FixedThreadPool( max, './tests/worker-files/thread/testWorker.js' ) @@ -299,6 +299,29 @@ describe('Selection strategies test suite', () => { ).end ).toBe(0) } + await pool.destroy() + pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js' + ) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy + .workerLastVirtualTaskTimestamp + ).toBeUndefined() + pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE) + for (const worker of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) { + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get( + worker + ).start + ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get( + worker + ).end + ).toBe(0) + } // We need to clean up the resources after our test await pool.destroy() }) @@ -388,7 +411,7 @@ describe('Selection strategies test suite', () => { }) it('Verify WEIGHTED_ROUND_ROBIN strategy statistics are resets after setting it', async () => { - const pool = new FixedThreadPool( + let pool = new FixedThreadPool( max, './tests/worker-files/thread/testWorker.js' ) @@ -403,6 +426,24 @@ describe('Selection strategies test suite', () => { ).runTime ).toBe(0) } + await pool.destroy() + pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js' + ) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy + .workersTaskRunTime + ).toBeUndefined() + pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN) + for (const worker of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workersTaskRunTime.keys()) { + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workersTaskRunTime.get( + worker + ).runTime + ).toBe(0) + } // We need to clean up the resources after our test await pool.destroy() }) -- 2.34.1