From: Jérôme Benoit Date: Wed, 12 Oct 2022 13:50:36 +0000 (+0200) Subject: Tests: assess internal strategy statistics resets at changing it X-Git-Tag: v2.3.1~16 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=caeb9817ea6f4c4b7b89839d4e03d0eccd44de76;p=poolifier.git Tests: assess internal strategy statistics resets at changing it Signed-off-by: Jérôme Benoit --- 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( () =>