Tests: also test strategy statistics reset on dynamic pool
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 12 Oct 2022 17:11:38 +0000 (19:11 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 12 Oct 2022 17:11:38 +0000 (19:11 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
tests/pools/selection-strategies/selection-strategies.test.js

index ce1b43136b17c3103f84fe772c0b01bef7519b8c..7b11bf402e06f981d53dda669809808dbb3c9ca8 100644 (file)
@@ -278,7 +278,7 @@ describe('Selection strategies test suite', () => {
   })
 
   it('Verify FAIR_SHARE strategy statistics are resets after setting it', async () => {
-    const pool = new FixedThreadPool(
+    let pool = new FixedThreadPool(
       max,
       './tests/worker-files/thread/testWorker.js'
     )
@@ -299,6 +299,29 @@ describe('Selection strategies test suite', () => {
         ).end
       ).toBe(0)
     }
+    await pool.destroy()
+    pool = new DynamicThreadPool(
+      min,
+      max,
+      './tests/worker-files/thread/testWorker.js'
+    )
+    expect(
+      pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
+        .workerLastVirtualTaskTimestamp
+    ).toBeUndefined()
+    pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
+    for (const worker of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) {
+      expect(
+        pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
+          worker
+        ).start
+      ).toBe(0)
+      expect(
+        pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
+          worker
+        ).end
+      ).toBe(0)
+    }
     // We need to clean up the resources after our test
     await pool.destroy()
   })
@@ -388,7 +411,7 @@ describe('Selection strategies test suite', () => {
   })
 
   it('Verify WEIGHTED_ROUND_ROBIN strategy statistics are resets after setting it', async () => {
-    const pool = new FixedThreadPool(
+    let pool = new FixedThreadPool(
       max,
       './tests/worker-files/thread/testWorker.js'
     )
@@ -403,6 +426,24 @@ describe('Selection strategies test suite', () => {
         ).runTime
       ).toBe(0)
     }
+    await pool.destroy()
+    pool = new DynamicThreadPool(
+      min,
+      max,
+      './tests/worker-files/thread/testWorker.js'
+    )
+    expect(
+      pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
+        .workersTaskRunTime
+    ).toBeUndefined()
+    pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+    for (const worker of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workersTaskRunTime.keys()) {
+      expect(
+        pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workersTaskRunTime.get(
+          worker
+        ).runTime
+      ).toBe(0)
+    }
     // We need to clean up the resources after our test
     await pool.destroy()
   })