test: improve worker choice strategies testing
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 30 May 2023 13:08:02 +0000 (15:08 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 30 May 2023 13:08:02 +0000 (15:08 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
.eslintrc.js
tests/pools/cluster/dynamic.test.js
tests/pools/cluster/fixed.test.js
tests/pools/selection-strategies/selection-strategies.test.js
tests/pools/thread/dynamic.test.js
tests/pools/thread/fixed.test.js

index 0b465dadff597167df9220f9715c1f8724b010c3..d7004cc55ff8460161f54f766086dd78d7612eb8 100644 (file)
@@ -38,10 +38,6 @@ module.exports = defineConfig({
       {
         skipWords: [
           'Benoit',
-          'Uint8',
-          'Uint16',
-          'Uint32',
-          'Uint64',
           'benny',
           'browserslist',
           'builtins',
index 6d2bccadc1f2ae9bce01904443bb475b56ccb6a6..c737c1d90ebc08743d5ae2a0af99c8957433376c 100644 (file)
@@ -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)
index 8234fab9a5f4f4e62b72f8ecdabd51b94f046c4d..42f03b893d7c4f950e1950d3a23a5aec64fb88f4 100644 (file)
@@ -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())
index 94263ab49da7eb191206b399fc00876dd5115fd7..977706cce8a7e5c913d483b6e97edf6572b3f3f1 100644 (file)
@@ -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(
index 959693901b22a6f9bda1d8d7be607cc8a40e82cc..1f2a646355b04ba8b10908edd1bda43c817c43f9 100644 (file)
@@ -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)
index aed2b3c193ffe90977fa9f853aa670f0eaff51b5..2d689feda6a86b2fda9f03fbbbd2d62fec6f9bef 100644 (file)
@@ -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())