From caeb9817ea6f4c4b7b89839d4e03d0eccd44de76 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 12 Oct 2022 15:50:36 +0200 Subject: [PATCH] Tests: assess internal strategy statistics resets at changing it MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- package-lock.json | 14 +++--- package.json | 2 +- .../dynamic-pool-worker-choice-strategy.ts | 2 +- .../selection-strategies.test.js | 46 +++++++++++++++++++ 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4923bb9e..c0d884c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,7 +34,7 @@ "prettier": "^2.7.1", "prettier-plugin-organize-imports": "^3.1.1", "prettierx": "^0.18.3", - "rollup": "^3.0.0", + "rollup": "^3.1.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-command": "^1.1.3", "rollup-plugin-delete": "^2.0.0", @@ -6890,9 +6890,9 @@ } }, "node_modules/rollup": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.0.0.tgz", - "integrity": "sha512-iVomS2lySi4BM2QJb7lGZBjSndUEs6Ip+VDl25jcbM99VI5vWeEitvUSiNQkQkwqEiI4515m5shjyuwPcXS5Dg==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.1.0.tgz", + "integrity": "sha512-GEvr+COcXicr4nuih6mpt2Eydq5lZ72z0RrKx1H4/Q2ouT34OHrIIJ9OUj2sZqUhq7QL8Hp8Q8BoWbjL/6ccRQ==", "dev": true, "bin": { "rollup": "dist/bin/rollup" @@ -13440,9 +13440,9 @@ } }, "rollup": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.0.0.tgz", - "integrity": "sha512-iVomS2lySi4BM2QJb7lGZBjSndUEs6Ip+VDl25jcbM99VI5vWeEitvUSiNQkQkwqEiI4515m5shjyuwPcXS5Dg==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.1.0.tgz", + "integrity": "sha512-GEvr+COcXicr4nuih6mpt2Eydq5lZ72z0RrKx1H4/Q2ouT34OHrIIJ9OUj2sZqUhq7QL8Hp8Q8BoWbjL/6ccRQ==", "dev": true, "requires": { "fsevents": "~2.3.2" diff --git a/package.json b/package.json index 109567d2..3939a32a 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "prettier": "^2.7.1", "prettier-plugin-organize-imports": "^3.1.1", "prettierx": "^0.18.3", - "rollup": "^3.0.0", + "rollup": "^3.1.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-command": "^1.1.3", "rollup-plugin-delete": "^2.0.0", diff --git a/src/pools/selection-strategies/dynamic-pool-worker-choice-strategy.ts b/src/pools/selection-strategies/dynamic-pool-worker-choice-strategy.ts index a4cd8b98..8d8b8518 100644 --- a/src/pools/selection-strategies/dynamic-pool-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/dynamic-pool-worker-choice-strategy.ts @@ -54,7 +54,7 @@ export class DynamicPoolWorkerChoiceStrategy< return freeWorker } - if (this.pool.busy) { + if (this.pool.busy === true) { return this.workerChoiceStrategy.choose() } diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index da4fea96..ce1b4313 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -277,6 +277,32 @@ describe('Selection strategies test suite', () => { await pool.destroy() }) + it('Verify FAIR_SHARE strategy statistics are resets after setting it', async () => { + const pool = new FixedThreadPool( + max, + './tests/worker-files/thread/testWorker.js' + ) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategy + .workerLastVirtualTaskTimestamp + ).toBeUndefined() + pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE) + for (const worker of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) { + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get( + worker + ).start + ).toBe(0) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get( + worker + ).end + ).toBe(0) + } + // We need to clean up the resources after our test + await pool.destroy() + }) + it('Verify WEIGHTED_ROUND_ROBIN strategy is taken at pool creation', async () => { const pool = new FixedThreadPool( max, @@ -361,6 +387,26 @@ describe('Selection strategies test suite', () => { await pool.destroy() }) + it('Verify WEIGHTED_ROUND_ROBIN strategy statistics are resets after setting it', async () => { + const pool = new FixedThreadPool( + max, + './tests/worker-files/thread/testWorker.js' + ) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime + ).toBeUndefined() + pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN) + for (const worker of pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.keys()) { + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get( + worker + ).runTime + ).toBe(0) + } + // We need to clean up the resources after our test + await pool.destroy() + }) + it('Verify unknown strategies throw error', () => { expect( () => -- 2.34.1