test: add least elu strategy test with dynamic pool
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 9 Jun 2023 11:12:49 +0000 (13:12 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 9 Jun 2023 11:12:49 +0000 (13:12 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
CHANGELOG.md
tests/pools/selection-strategies/selection-strategies.test.js

index c487a4971190fc9de05513e9de04bed59a7bea2c..ac82cb248d737484421f123027f255364066a6d1 100644 (file)
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+### Added
+
+- Add `LEST_ELU` worker choice strategy.
+
 ### Changed
 
 - Refactor pool worker node usage internals.
index 8e226860c2e3a018cda341a26959deb11ae88ed5..9e69c330c09272d382da24339f3b323568807063 100644 (file)
@@ -699,6 +699,64 @@ describe('Selection strategies test suite', () => {
     await pool.destroy()
   })
 
+  it('Verify LEAST_ELU strategy can be run in a dynamic pool', async () => {
+    const pool = new DynamicThreadPool(
+      min,
+      max,
+      './tests/worker-files/thread/testWorker.js',
+      { workerChoiceStrategy: WorkerChoiceStrategies.LEAST_ELU }
+    )
+    // TODO: Create a better test to cover `LeastEluWorkerChoiceStrategy#choose`
+    const maxMultiplier = 2
+    for (let i = 0; i < max * maxMultiplier; i++) {
+      await pool.execute()
+      if (i !== max * maxMultiplier - 1) await TestUtils.sleep(500)
+    }
+    for (const workerNode of pool.workerNodes) {
+      const expectedWorkerUsage = {
+        tasks: {
+          executed: expect.any(Number),
+          executing: 0,
+          queued: 0,
+          failed: 0
+        },
+        runTime: {
+          aggregate: 0,
+          average: 0,
+          median: 0,
+          history: expect.any(CircularArray)
+        },
+        waitTime: {
+          aggregate: 0,
+          average: 0,
+          median: 0,
+          history: expect.any(CircularArray)
+        }
+      }
+      if (workerNode.workerUsage.elu === undefined) {
+        expect(workerNode.workerUsage).toStrictEqual({
+          ...expectedWorkerUsage,
+          elu: undefined
+        })
+      } else {
+        expect(workerNode.workerUsage).toStrictEqual({
+          ...expectedWorkerUsage,
+          elu: {
+            active: expect.any(Number),
+            idle: 0,
+            utilization: 1
+          }
+        })
+      }
+      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()
+  })
+
   it('Verify FAIR_SHARE strategy default tasks usage statistics requirements', async () => {
     const workerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE
     let pool = new FixedThreadPool(