Improve tests coverage on worker choice strategies
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 13 Oct 2022 20:19:44 +0000 (22:19 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 13 Oct 2022 20:19:44 +0000 (22:19 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
package-lock.json
package.json
tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.js
tests/test-utils.js

index 1f1d18d66629e8b79bc86448788c972452983144..5d7576b4548a183084bc807078a44e4a16e1668f 100644 (file)
@@ -22,7 +22,7 @@
         "eslint-plugin-n": "^15.3.0",
         "eslint-plugin-node": "^11.1.0",
         "eslint-plugin-prettierx": "^0.18.0",
-        "eslint-plugin-promise": "^6.0.1",
+        "eslint-plugin-promise": "^6.1.0",
         "eslint-plugin-spellcheck": "^0.0.19",
         "expect": "^29.1.2",
         "husky": "^8.0.1",
       }
     },
     "node_modules/eslint-plugin-promise": {
-      "version": "6.0.1",
-      "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-6.0.1.tgz",
-      "integrity": "sha512-uM4Tgo5u3UWQiroOyDEsYcVMOo7re3zmno0IZmB5auxoaQNIceAbXEkSt8RNrKtaYehARHG06pYK6K1JhtP0Zw==",
+      "version": "6.1.0",
+      "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-6.1.0.tgz",
+      "integrity": "sha512-NYCfDZF/KHt27p06nFAttgWuFyIDSUMnNaJBIY1FY9GpBFhdT2vMG64HlFguSgcJeyM5by6Yr5csSOuJm60eXQ==",
       "dev": true,
       "engines": {
         "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
       }
     },
     "eslint-plugin-promise": {
-      "version": "6.0.1",
-      "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-6.0.1.tgz",
-      "integrity": "sha512-uM4Tgo5u3UWQiroOyDEsYcVMOo7re3zmno0IZmB5auxoaQNIceAbXEkSt8RNrKtaYehARHG06pYK6K1JhtP0Zw==",
+      "version": "6.1.0",
+      "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-6.1.0.tgz",
+      "integrity": "sha512-NYCfDZF/KHt27p06nFAttgWuFyIDSUMnNaJBIY1FY9GpBFhdT2vMG64HlFguSgcJeyM5by6Yr5csSOuJm60eXQ==",
       "dev": true
     },
     "eslint-plugin-spellcheck": {
index a425e783289c53de8d6fde6ed5208e45084021ab..7ede58c335ac9d43af395d79bf09413a6d4651d4 100644 (file)
@@ -77,7 +77,7 @@
     "eslint-plugin-n": "^15.3.0",
     "eslint-plugin-node": "^11.1.0",
     "eslint-plugin-prettierx": "^0.18.0",
-    "eslint-plugin-promise": "^6.0.1",
+    "eslint-plugin-promise": "^6.1.0",
     "eslint-plugin-spellcheck": "^0.0.19",
     "expect": "^29.1.2",
     "husky": "^8.0.1",
index 24246595e6bdc92bcd40afad6638c31ef3842e83..41c7751cc61d75eabc1762c7f3296f0f08945e9d 100644 (file)
@@ -4,6 +4,7 @@ const { FixedThreadPool } = require('../../../lib/index')
 const {
   WeightedRoundRobinWorkerChoiceStrategy
 } = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy')
+const TestUtils = require('../../test-utils')
 
 describe('Weighted round robin strategy worker choice strategy test suite', () => {
   // const min = 1
@@ -24,6 +25,12 @@ describe('Weighted round robin strategy worker choice strategy test suite', () =
 
   it('Verify that reset() resets internals', () => {
     const strategy = new WeightedRoundRobinWorkerChoiceStrategy(pool)
+    strategy.previousWorkerIndex = TestUtils.generateRandomInteger(
+      Number.MAX_SAFE_INTEGER
+    )
+    strategy.currentWorkerIndex = TestUtils.generateRandomInteger(
+      Number.MAX_SAFE_INTEGER
+    )
     const workersTaskRunTimeClearStub = sinon
       .stub(strategy.workersTaskRunTime, 'clear')
       .returns()
@@ -34,7 +41,6 @@ describe('Weighted round robin strategy worker choice strategy test suite', () =
     expect(resetResult).toBe(true)
     expect(strategy.previousWorkerIndex).toBe(0)
     expect(strategy.currentWorkerIndex).toBe(0)
-    expect(strategy.defaultWorkerWeight).toBeGreaterThan(0)
     expect(workersTaskRunTimeClearStub.calledOnce).toBe(true)
     expect(initWorkersTaskRunTimeStub.calledOnce).toBe(true)
   })
index 78218e2668c34bbfef44e680e1e9676eccf7b7cd..a3affb61c91899d187dd91e97f2693cfa7340d0d 100644 (file)
@@ -36,6 +36,15 @@ class TestUtils {
     })
   }
 
+  static generateRandomInteger (max, min = 0) {
+    max = Math.floor(max)
+    if (min) {
+      min = Math.ceil(min)
+      return Math.floor(Math.random() * (max - min + 1)) + min
+    }
+    return Math.floor(Math.random() * (max + 1))
+  }
+
   static jsonIntegerSerialization (n) {
     for (let i = 0; i < n; i++) {
       const o = {