fix: updates strategies internals once statistics are computed
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 17 Jun 2023 13:01:23 +0000 (15:01 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 17 Jun 2023 13:01:23 +0000 (15:01 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/abstract-pool.ts
src/pools/selection-strategies/selection-strategies-types.ts
tests/pools/selection-strategies/selection-strategies.test.js

index 1341c9afdd8b867faea351389a6f2792b21e7bc6..a042e873fef452a603b9837630b323f0da1abaf7 100644 (file)
@@ -421,7 +421,6 @@ export abstract class AbstractPool<
     } else {
       this.executeTask(workerNodeKey, submittedTask)
     }
-    this.workerChoiceStrategyContext.update(workerNodeKey)
     this.checkAndEmitEvents()
     // eslint-disable-next-line @typescript-eslint/return-await
     return res
index 7a5a10c6018fda998f61143c42b47fb9bd4d8e41..ac2ee6c3ca6b97f96c0e16a8ccf04e9557246090 100644 (file)
@@ -147,7 +147,7 @@ export interface TaskStatisticsRequirements {
  */
 export interface StrategyPolicy {
   /**
-   * Expect direct usage of dynamic worker.
+   * Expects direct usage of dynamic worker.
    */
   useDynamicWorker: boolean
 }
index d7567114ed67d35f9288bd1399c327ac6d9911f4..6091bf080f327a3218f53522fcfd1780ef543a70 100644 (file)
@@ -476,7 +476,7 @@ describe('Selection strategies test suite', () => {
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.workerUsage).toStrictEqual({
         tasks: {
-          executed: maxMultiplier,
+          executed: expect.any(Number),
           executing: 0,
           queued: 0,
           failed: 0
@@ -509,6 +509,10 @@ describe('Selection strategies test suite', () => {
           utilization: 0
         }
       })
+      expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0)
+      expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual(
+        max * maxMultiplier
+      )
     }
     // We need to clean up the resources after our test
     await pool.destroy()
@@ -531,7 +535,7 @@ describe('Selection strategies test suite', () => {
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.workerUsage).toStrictEqual({
         tasks: {
-          executed: maxMultiplier,
+          executed: expect.any(Number),
           executing: 0,
           queued: 0,
           failed: 0
@@ -564,6 +568,10 @@ describe('Selection strategies test suite', () => {
           utilization: 0
         }
       })
+      expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0)
+      expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual(
+        max * maxMultiplier
+      )
     }
     // We need to clean up the resources after our test
     await pool.destroy()
@@ -698,7 +706,7 @@ describe('Selection strategies test suite', () => {
           utilization: 0
         }
       })
-      expect(workerNode.workerUsage.tasks.executed).toBeGreaterThan(0)
+      expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0)
       expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual(
         max * maxMultiplier
       )
@@ -761,12 +769,14 @@ describe('Selection strategies test suite', () => {
           utilization: 0
         }
       })
-      expect(workerNode.workerUsage.tasks.executed).toBeGreaterThan(0)
+      expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0)
       expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual(
         max * maxMultiplier
       )
-      expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThan(0)
-      expect(workerNode.workerUsage.waitTime.aggregate).toBeGreaterThan(0)
+      expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThanOrEqual(0)
+      expect(workerNode.workerUsage.waitTime.aggregate).toBeGreaterThanOrEqual(
+        0
+      )
     }
     // We need to clean up the resources after our test
     await pool.destroy()
@@ -1106,8 +1116,8 @@ describe('Selection strategies test suite', () => {
       expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual(
         max * maxMultiplier
       )
-      expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThan(0)
-      expect(workerNode.workerUsage.runTime.average).toBeGreaterThan(0)
+      expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThanOrEqual(0)
+      expect(workerNode.workerUsage.runTime.average).toBeGreaterThanOrEqual(0)
       expect(workerNode.workerUsage.elu.utilization).toBeGreaterThanOrEqual(0)
       expect(workerNode.workerUsage.elu.utilization).toBeLessThanOrEqual(1)
     }