From: Jérôme Benoit Date: Fri, 14 Apr 2023 22:50:39 +0000 (+0200) Subject: test: add tests for worker choice strategies using median run time X-Git-Tag: v2.4.9~17 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=010d7020b316c0dd9a7a95a3ae1cba074ab2303e;p=poolifier.git test: add tests for worker choice strategies using median run time 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 2fcbba5a..dde60e26 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -478,6 +478,42 @@ describe('Selection strategies test suite', () => { await pool.destroy() }) + it('Verify FAIR_SHARE strategy can be run in a dynamic pool with median run time statistic', async () => { + const pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js', + { + workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE, + workerChoiceStrategyOptions: { + medRunTime: true + } + } + ) + // TODO: Create a better test to cover `FairShareChoiceStrategy#choose` + const promises = [] + const maxMultiplier = 2 + for (let i = 0; i < max * maxMultiplier; i++) { + promises.push(pool.execute()) + } + await Promise.all(promises) + for (const workerNode of pool.workerNodes) { + expect(workerNode.tasksUsage.avgRunTime).toBeDefined() + expect(workerNode.tasksUsage.avgRunTime).toBe(0) + expect(workerNode.tasksUsage.medRunTime).toBeDefined() + expect(workerNode.tasksUsage.medRunTime).toBeGreaterThan(0) + } + // if (process.platform !== 'win32') { + // expect( + // pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + // pool.workerChoiceStrategyContext.workerChoiceStrategy + // ).workerLastVirtualTaskTimestamp.size + // ).toBe(pool.workerNodes.length) + // } + // We need to clean up the resources after our test + await pool.destroy() + }) + it('Verify FAIR_SHARE strategy internals are resets after setting it', async () => { const workerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE let pool = new FixedThreadPool( @@ -619,6 +655,42 @@ describe('Selection strategies test suite', () => { await pool.destroy() }) + it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool with median run time statistic', async () => { + const pool = new DynamicThreadPool( + min, + max, + './tests/worker-files/thread/testWorker.js', + { + workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN, + workerChoiceStrategyOptions: { + medRunTime: true + } + } + ) + // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose` + const promises = [] + const maxMultiplier = 2 + for (let i = 0; i < max * maxMultiplier; i++) { + promises.push(pool.execute()) + } + await Promise.all(promises) + for (const workerNode of pool.workerNodes) { + expect(workerNode.tasksUsage.avgRunTime).toBeDefined() + expect(workerNode.tasksUsage.avgRunTime).toBe(0) + expect(workerNode.tasksUsage.medRunTime).toBeDefined() + expect(workerNode.tasksUsage.medRunTime).toBeGreaterThan(0) + } + // if (process.platform !== 'win32') { + // expect( + // pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + // pool.workerChoiceStrategyContext.workerChoiceStrategy + // ).workersTaskRunTime.size + // ).toBe(pool.workerNodes.length) + // } + // We need to clean up the resources after our test + await pool.destroy() + }) + it('Verify WEIGHTED_ROUND_ROBIN strategy internals are resets after setting it', async () => { const workerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN let pool = new FixedThreadPool(