Tests: assess internal strategy statistics resets at changing it
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 12 Oct 2022 13:50:36 +0000 (15:50 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 12 Oct 2022 13:50:36 +0000 (15:50 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
package-lock.json
package.json
src/pools/selection-strategies/dynamic-pool-worker-choice-strategy.ts
tests/pools/selection-strategies/selection-strategies.test.js

index 4923bb9e95a3762396320514d59c5c3de2e10a68..c0d884c321941a0f55ebf1932f77beef3fdc7b87 100644 (file)
@@ -34,7 +34,7 @@
         "prettier": "^2.7.1",
         "prettier-plugin-organize-imports": "^3.1.1",
         "prettierx": "^0.18.3",
-        "rollup": "^3.0.0",
+        "rollup": "^3.1.0",
         "rollup-plugin-analyzer": "^4.0.0",
         "rollup-plugin-command": "^1.1.3",
         "rollup-plugin-delete": "^2.0.0",
       }
     },
     "node_modules/rollup": {
-      "version": "3.0.0",
-      "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.0.0.tgz",
-      "integrity": "sha512-iVomS2lySi4BM2QJb7lGZBjSndUEs6Ip+VDl25jcbM99VI5vWeEitvUSiNQkQkwqEiI4515m5shjyuwPcXS5Dg==",
+      "version": "3.1.0",
+      "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.1.0.tgz",
+      "integrity": "sha512-GEvr+COcXicr4nuih6mpt2Eydq5lZ72z0RrKx1H4/Q2ouT34OHrIIJ9OUj2sZqUhq7QL8Hp8Q8BoWbjL/6ccRQ==",
       "dev": true,
       "bin": {
         "rollup": "dist/bin/rollup"
       }
     },
     "rollup": {
-      "version": "3.0.0",
-      "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.0.0.tgz",
-      "integrity": "sha512-iVomS2lySi4BM2QJb7lGZBjSndUEs6Ip+VDl25jcbM99VI5vWeEitvUSiNQkQkwqEiI4515m5shjyuwPcXS5Dg==",
+      "version": "3.1.0",
+      "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.1.0.tgz",
+      "integrity": "sha512-GEvr+COcXicr4nuih6mpt2Eydq5lZ72z0RrKx1H4/Q2ouT34OHrIIJ9OUj2sZqUhq7QL8Hp8Q8BoWbjL/6ccRQ==",
       "dev": true,
       "requires": {
         "fsevents": "~2.3.2"
index 109567d26450b71264dd9bb568d69990c4daa1f6..3939a32a35c99775ed255bbbba2776a29a96515b 100644 (file)
@@ -89,7 +89,7 @@
     "prettier": "^2.7.1",
     "prettier-plugin-organize-imports": "^3.1.1",
     "prettierx": "^0.18.3",
-    "rollup": "^3.0.0",
+    "rollup": "^3.1.0",
     "rollup-plugin-analyzer": "^4.0.0",
     "rollup-plugin-command": "^1.1.3",
     "rollup-plugin-delete": "^2.0.0",
index a4cd8b986744621789436dd6709151230e59b176..8d8b8518a4bd110d6453261d83ac8dd932254308 100644 (file)
@@ -54,7 +54,7 @@ export class DynamicPoolWorkerChoiceStrategy<
       return freeWorker
     }
 
-    if (this.pool.busy) {
+    if (this.pool.busy === true) {
       return this.workerChoiceStrategy.choose()
     }
 
index da4fea96e1557401f9bafde36c6416a8a6b50d39..ce1b43136b17c3103f84fe772c0b01bef7519b8c 100644 (file)
@@ -277,6 +277,32 @@ describe('Selection strategies test suite', () => {
     await pool.destroy()
   })
 
+  it('Verify FAIR_SHARE strategy statistics are resets after setting it', async () => {
+    const pool = new FixedThreadPool(
+      max,
+      './tests/worker-files/thread/testWorker.js'
+    )
+    expect(
+      pool.workerChoiceStrategyContext.workerChoiceStrategy
+        .workerLastVirtualTaskTimestamp
+    ).toBeUndefined()
+    pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
+    for (const worker of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) {
+      expect(
+        pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
+          worker
+        ).start
+      ).toBe(0)
+      expect(
+        pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
+          worker
+        ).end
+      ).toBe(0)
+    }
+    // We need to clean up the resources after our test
+    await pool.destroy()
+  })
+
   it('Verify WEIGHTED_ROUND_ROBIN strategy is taken at pool creation', async () => {
     const pool = new FixedThreadPool(
       max,
@@ -361,6 +387,26 @@ describe('Selection strategies test suite', () => {
     await pool.destroy()
   })
 
+  it('Verify WEIGHTED_ROUND_ROBIN strategy statistics are resets after setting it', async () => {
+    const pool = new FixedThreadPool(
+      max,
+      './tests/worker-files/thread/testWorker.js'
+    )
+    expect(
+      pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime
+    ).toBeUndefined()
+    pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+    for (const worker of pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.keys()) {
+      expect(
+        pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get(
+          worker
+        ).runTime
+      ).toBe(0)
+    }
+    // We need to clean up the resources after our test
+    await pool.destroy()
+  })
+
   it('Verify unknown strategies throw error', () => {
     expect(
       () =>