From: Jérôme Benoit Date: Wed, 12 Oct 2022 17:11:38 +0000 (+0200) Subject: Tests: also test strategy statistics reset on dynamic pool X-Git-Tag: v2.3.1~15 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=f0829c537c1be61af8472ce3167d7a58fe0c8e69;p=poolifier.git Tests: also test strategy statistics reset on dynamic pool Signed-off-by: Jérôme Benoit --- 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() })