From e211bc1861384013439097460a1bfb45e76eedd6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 30 May 2023 15:08:02 +0200 Subject: [PATCH] test: improve worker choice strategies testing MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .eslintrc.js | 4 - tests/pools/cluster/dynamic.test.js | 8 +- tests/pools/cluster/fixed.test.js | 2 +- .../selection-strategies.test.js | 182 +++++++++++++++--- tests/pools/thread/dynamic.test.js | 8 +- tests/pools/thread/fixed.test.js | 2 +- 6 files changed, 167 insertions(+), 39 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 0b465dad..d7004cc5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -38,10 +38,6 @@ module.exports = defineConfig({ { skipWords: [ 'Benoit', - 'Uint8', - 'Uint16', - 'Uint32', - 'Uint64', 'benny', 'browserslist', 'builtins', diff --git a/tests/pools/cluster/dynamic.test.js b/tests/pools/cluster/dynamic.test.js index 6d2bccad..c737c1d9 100644 --- a/tests/pools/cluster/dynamic.test.js +++ b/tests/pools/cluster/dynamic.test.js @@ -43,13 +43,13 @@ describe('Dynamic cluster pool test suite', () => { it('Verify scale worker up and down is working', async () => { expect(pool.workerNodes.length).toBe(min) - for (let i = 0; i < max * 10; i++) { + for (let i = 0; i < max * 2; i++) { pool.execute() } expect(pool.workerNodes.length).toBeGreaterThan(min) await TestUtils.waitExits(pool, max - min) expect(pool.workerNodes.length).toBe(min) - for (let i = 0; i < max * 10; i++) { + for (let i = 0; i < max * 2; i++) { pool.execute() } expect(pool.workerNodes.length).toBeGreaterThan(min) @@ -94,7 +94,7 @@ describe('Dynamic cluster pool test suite', () => { } ) expect(longRunningPool.workerNodes.length).toBe(min) - for (let i = 0; i < max * 10; i++) { + for (let i = 0; i < max * 2; i++) { longRunningPool.execute() } expect(longRunningPool.workerNodes.length).toBe(max) @@ -121,7 +121,7 @@ describe('Dynamic cluster pool test suite', () => { } ) expect(longRunningPool.workerNodes.length).toBe(min) - for (let i = 0; i < max * 10; i++) { + for (let i = 0; i < max * 2; i++) { longRunningPool.execute() } expect(longRunningPool.workerNodes.length).toBe(max) diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 8234fab9..42f03b89 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -89,7 +89,7 @@ describe('Fixed cluster pool test suite', () => { }) it('Verify that tasks queuing is working', async () => { - const maxMultiplier = 10 + const maxMultiplier = 2 const promises = new Set() for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) { promises.add(queuePool.execute()) diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index 94263ab4..977706cc 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -156,9 +156,27 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy: WorkerChoiceStrategies.ROUND_ROBIN } ) // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose` + const promises = [] const maxMultiplier = 2 for (let i = 0; i < max * maxMultiplier; i++) { - await pool.execute() + promises.push(pool.execute()) + } + await Promise.all(promises) + for (const workerNode of pool.workerNodes) { + expect(workerNode.tasksUsage).toStrictEqual({ + run: expect.any(Number), + running: 0, + runTime: 0, + runTimeHistory: expect.any(CircularArray), + avgRunTime: 0, + medRunTime: 0, + waitTime: 0, + waitTimeHistory: expect.any(CircularArray), + avgWaitTime: 0, + medWaitTime: 0, + error: 0 + }) + expect(workerNode.tasksUsage.run).toBeGreaterThan(0) } // We need to clean up the resources after our test await pool.destroy() @@ -172,9 +190,27 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy: WorkerChoiceStrategies.ROUND_ROBIN } ) // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose` + const promises = [] const maxMultiplier = 2 for (let i = 0; i < max * maxMultiplier; i++) { - await pool.execute() + promises.push(pool.execute()) + } + await Promise.all(promises) + for (const workerNode of pool.workerNodes) { + expect(workerNode.tasksUsage).toStrictEqual({ + run: expect.any(Number), + running: 0, + runTime: 0, + runTimeHistory: expect.any(CircularArray), + avgRunTime: 0, + medRunTime: 0, + waitTime: 0, + waitTimeHistory: expect.any(CircularArray), + avgWaitTime: 0, + medWaitTime: 0, + error: 0 + }) + expect(workerNode.tasksUsage.run).toBeGreaterThan(0) } // We need to clean up the resources after our test await pool.destroy() @@ -291,9 +327,27 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED } ) // TODO: Create a better test to cover `LeastUsedWorkerChoiceStrategy#choose` + const promises = [] const maxMultiplier = 2 for (let i = 0; i < max * maxMultiplier; i++) { - await pool.execute() + promises.push(pool.execute()) + } + await Promise.all(promises) + for (const workerNode of pool.workerNodes) { + expect(workerNode.tasksUsage).toStrictEqual({ + run: expect.any(Number), + running: 0, + runTime: 0, + runTimeHistory: expect.any(CircularArray), + avgRunTime: 0, + medRunTime: 0, + waitTime: 0, + waitTimeHistory: expect.any(CircularArray), + avgWaitTime: 0, + medWaitTime: 0, + error: 0 + }) + expect(workerNode.tasksUsage.run).toBeGreaterThan(0) } // We need to clean up the resources after our test await pool.destroy() @@ -307,9 +361,27 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED } ) // TODO: Create a better test to cover `LeastUsedWorkerChoiceStrategy#choose` + const promises = [] const maxMultiplier = 2 for (let i = 0; i < max * maxMultiplier; i++) { - await pool.execute() + promises.push(pool.execute()) + } + await Promise.all(promises) + for (const workerNode of pool.workerNodes) { + expect(workerNode.tasksUsage).toStrictEqual({ + run: expect.any(Number), + running: 0, + runTime: 0, + runTimeHistory: expect.any(CircularArray), + avgRunTime: 0, + medRunTime: 0, + waitTime: 0, + waitTimeHistory: expect.any(CircularArray), + avgWaitTime: 0, + medWaitTime: 0, + error: 0 + }) + expect(workerNode.tasksUsage.run).toBeGreaterThan(0) } // We need to clean up the resources after our test await pool.destroy() @@ -360,9 +432,28 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy: WorkerChoiceStrategies.LEAST_BUSY } ) // TODO: Create a better test to cover `LeastBusyWorkerChoiceStrategy#choose` + const promises = [] const maxMultiplier = 2 for (let i = 0; i < max * maxMultiplier; i++) { - await pool.execute() + promises.push(pool.execute()) + } + await Promise.all(promises) + for (const workerNode of pool.workerNodes) { + expect(workerNode.tasksUsage).toStrictEqual({ + run: expect.any(Number), + running: 0, + runTime: expect.any(Number), + runTimeHistory: expect.any(CircularArray), + avgRunTime: 0, + medRunTime: 0, + waitTime: 0, + waitTimeHistory: expect.any(CircularArray), + avgWaitTime: 0, + medWaitTime: 0, + error: 0 + }) + expect(workerNode.tasksUsage.run).toBeGreaterThan(0) + expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0) } // We need to clean up the resources after our test await pool.destroy() @@ -376,9 +467,28 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy: WorkerChoiceStrategies.LEAST_BUSY } ) // TODO: Create a better test to cover `LeastBusyWorkerChoiceStrategy#choose` + const promises = [] const maxMultiplier = 2 for (let i = 0; i < max * maxMultiplier; i++) { - await pool.execute() + promises.push(pool.execute()) + } + await Promise.all(promises) + for (const workerNode of pool.workerNodes) { + expect(workerNode.tasksUsage).toStrictEqual({ + run: expect.any(Number), + running: 0, + runTime: expect.any(Number), + runTimeHistory: expect.any(CircularArray), + avgRunTime: 0, + medRunTime: 0, + waitTime: 0, + waitTimeHistory: expect.any(CircularArray), + avgWaitTime: 0, + medWaitTime: 0, + error: 0 + }) + expect(workerNode.tasksUsage.run).toBeGreaterThan(0) + expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0) } // We need to clean up the resources after our test await pool.destroy() @@ -429,13 +539,15 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE } ) // TODO: Create a better test to cover `FairShareChoiceStrategy#choose` + const promises = [] const maxMultiplier = 2 for (let i = 0; i < max * maxMultiplier; i++) { - await pool.execute() + promises.push(pool.execute()) } + await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: maxMultiplier, + run: expect.any(Number), running: 0, runTime: expect.any(Number), runTimeHistory: expect.any(CircularArray), @@ -447,7 +559,9 @@ describe('Selection strategies test suite', () => { medWaitTime: 0, error: 0 }) - expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThanOrEqual(0) + expect(workerNode.tasksUsage.run).toBeGreaterThan(0) + expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0) + expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThan(0) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -466,13 +580,15 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE } ) // TODO: Create a better test to cover `FairShareChoiceStrategy#choose` + const promises = [] const maxMultiplier = 2 for (let i = 0; i < max * maxMultiplier; i++) { - await pool.execute() + promises.push(pool.execute()) } + await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: max * maxMultiplier, + run: expect.any(Number), running: 0, runTime: expect.any(Number), runTimeHistory: expect.any(CircularArray), @@ -484,7 +600,9 @@ describe('Selection strategies test suite', () => { medWaitTime: 0, error: 0 }) - expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThanOrEqual(0) + expect(workerNode.tasksUsage.run).toBeGreaterThan(0) + expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0) + expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThan(0) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -508,13 +626,15 @@ describe('Selection strategies test suite', () => { } ) // TODO: Create a better test to cover `FairShareChoiceStrategy#choose` + const promises = [] const maxMultiplier = 2 for (let i = 0; i < max * maxMultiplier; i++) { - await pool.execute() + promises.push(pool.execute()) } + await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: max * maxMultiplier, + run: expect.any(Number), running: 0, runTime: expect.any(Number), runTimeHistory: expect.any(CircularArray), @@ -526,7 +646,9 @@ describe('Selection strategies test suite', () => { medWaitTime: 0, error: 0 }) - expect(workerNode.tasksUsage.medRunTime).toBeGreaterThanOrEqual(0) + expect(workerNode.tasksUsage.run).toBeGreaterThan(0) + expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0) + expect(workerNode.tasksUsage.medRunTime).toBeGreaterThan(0) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -656,14 +778,14 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN } ) // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose` + const promises = [] const maxMultiplier = 2 for (let i = 0; i < max * maxMultiplier; i++) { - await pool.execute() + promises.push(pool.execute()) } + await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - // FIXME: it should be: - // run: max * maxMultiplier, run: expect.any(Number), running: 0, runTime: expect.any(Number), @@ -676,7 +798,9 @@ describe('Selection strategies test suite', () => { medWaitTime: 0, error: 0 }) - expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThanOrEqual(0) + expect(workerNode.tasksUsage.run).toBeGreaterThan(0) + expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0) + expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThan(0) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -700,13 +824,15 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN } ) // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose` + const promises = [] const maxMultiplier = 2 for (let i = 0; i < max * maxMultiplier; i++) { - await pool.execute() + promises.push(pool.execute()) } + await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: max * maxMultiplier, + run: expect.any(Number), running: 0, runTime: expect.any(Number), runTimeHistory: expect.any(CircularArray), @@ -718,7 +844,9 @@ describe('Selection strategies test suite', () => { medWaitTime: 0, error: 0 }) - expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThanOrEqual(0) + expect(workerNode.tasksUsage.run).toBeGreaterThan(0) + expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0) + expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThan(0) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -747,13 +875,15 @@ describe('Selection strategies test suite', () => { } ) // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose` + const promises = [] const maxMultiplier = 2 for (let i = 0; i < max * maxMultiplier; i++) { - await pool.execute() + promises.push(pool.execute()) } + await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: max * maxMultiplier, + run: expect.any(Number), running: 0, runTime: expect.any(Number), runTimeHistory: expect.any(CircularArray), @@ -765,7 +895,9 @@ describe('Selection strategies test suite', () => { medWaitTime: 0, error: 0 }) - expect(workerNode.tasksUsage.medRunTime).toBeGreaterThanOrEqual(0) + expect(workerNode.tasksUsage.run).toBeGreaterThan(0) + expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0) + expect(workerNode.tasksUsage.medRunTime).toBeGreaterThan(0) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( diff --git a/tests/pools/thread/dynamic.test.js b/tests/pools/thread/dynamic.test.js index 95969390..1f2a6463 100644 --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.js @@ -43,13 +43,13 @@ describe('Dynamic thread pool test suite', () => { it('Verify scale thread up and down is working', async () => { expect(pool.workerNodes.length).toBe(min) - for (let i = 0; i < max * 10; i++) { + for (let i = 0; i < max * 2; i++) { pool.execute() } expect(pool.workerNodes.length).toBe(max) await TestUtils.waitExits(pool, max - min) expect(pool.workerNodes.length).toBe(min) - for (let i = 0; i < max * 10; i++) { + for (let i = 0; i < max * 2; i++) { pool.execute() } expect(pool.workerNodes.length).toBe(max) @@ -94,7 +94,7 @@ describe('Dynamic thread pool test suite', () => { } ) expect(longRunningPool.workerNodes.length).toBe(min) - for (let i = 0; i < max * 10; i++) { + for (let i = 0; i < max * 2; i++) { longRunningPool.execute() } expect(longRunningPool.workerNodes.length).toBe(max) @@ -121,7 +121,7 @@ describe('Dynamic thread pool test suite', () => { } ) expect(longRunningPool.workerNodes.length).toBe(min) - for (let i = 0; i < max * 10; i++) { + for (let i = 0; i < max * 2; i++) { longRunningPool.execute() } expect(longRunningPool.workerNodes.length).toBe(max) diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index aed2b3c1..2d689fed 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -89,7 +89,7 @@ describe('Fixed thread pool test suite', () => { }) it('Verify that tasks queuing is working', async () => { - const maxMultiplier = 10 + const maxMultiplier = 2 const promises = new Set() for (let i = 0; i < numberOfThreads * maxMultiplier; i++) { promises.add(queuePool.execute()) -- 2.34.1