fix: ensure the least busy strategy only relies on task runtime
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 6 Jun 2023 20:42:06 +0000 (22:42 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 6 Jun 2023 20:42:06 +0000 (22:42 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
CHANGELOG.md
src/pools/selection-strategies/least-busy-worker-choice-strategy.ts
tests/pools/selection-strategies/selection-strategies.test.js

index dc94cb94b0909ce6bde32179231c6d2a058f9e1c..cb62e716c66205533efeee5f60ddd4ac1b3a74ed 100644 (file)
@@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - Compute statistics at the worker level only if needed.
 
+### Fixed
+
+- Make the `LEAST_BUSY` strategy only relies on task runtime.
+
 ## [2.5.3] - 2023-06-04
 
 ### Changed
index 16b2988b93a290e83b9c6954820bbd6c9b5e2727..67332c70c4b21a895e97a3fa037526b5da57bc33 100644 (file)
@@ -54,10 +54,10 @@ export class LeastBusyWorkerChoiceStrategy<
 
   /** @inheritDoc */
   public choose (): number {
-    const freeWorkerNodeKey = this.findFreeWorkerNodeKey()
-    if (freeWorkerNodeKey !== -1) {
-      return freeWorkerNodeKey
-    }
+    // const freeWorkerNodeKey = this.findFreeWorkerNodeKey()
+    // if (freeWorkerNodeKey !== -1) {
+    //   return freeWorkerNodeKey
+    // }
     let minRunTime = Infinity
     let leastBusyWorkerNodeKey!: number
     for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
index eedee42765e25c475310b10a07e4fb50fee097fc..cf6f1601444d8f939c8b7dbea4ac884e59ec6a67 100644 (file)
@@ -460,9 +460,9 @@ describe('Selection strategies test suite', () => {
         error: 0,
         elu: undefined
       })
-      expect(workerNode.tasksUsage.ran).toBeGreaterThan(0)
+      expect(workerNode.tasksUsage.ran).toBeGreaterThanOrEqual(0)
       expect(workerNode.tasksUsage.ran).toBeLessThanOrEqual(max * maxMultiplier)
-      expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0)
+      expect(workerNode.tasksUsage.runTime).toBeGreaterThanOrEqual(0)
     }
     // We need to clean up the resources after our test
     await pool.destroy()