test: improve worker choice strategies coverage
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 21 Dec 2023 18:36:31 +0000 (19:36 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 21 Dec 2023 18:36:31 +0000 (19:36 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
tests/pools/abstract-pool.test.mjs

index 9cc284d60213267733a364ce3071d2b3a96d472b..c0ba50b07b37b63ea7c28eb5b8df8bef829ae529 100644 (file)
@@ -242,16 +242,18 @@ describe('Abstract pool test suite', () => {
     })
     for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
       .workerChoiceStrategies) {
-      expect(workerChoiceStrategy.opts).toStrictEqual(
-        expect.objectContaining({
-          retries:
-            pool.info.maxSize +
-            Object.keys(workerChoiceStrategy.opts.weights).length,
-          runTime: { median: false },
-          waitTime: { median: false },
-          elu: { median: false }
+      expect(workerChoiceStrategy.opts).toStrictEqual({
+        retries:
+          pool.info.maxSize +
+          Object.keys(workerChoiceStrategy.opts.weights).length,
+        runTime: { median: false },
+        waitTime: { median: false },
+        elu: { median: false },
+        weights: expect.objectContaining({
+          0: expect.any(Number),
+          [pool.info.maxSize - 1]: expect.any(Number)
         })
-      )
+      })
     }
     await pool.destroy()
     const testHandler = () => console.info('test handler executed')
@@ -482,16 +484,18 @@ describe('Abstract pool test suite', () => {
     })
     for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
       .workerChoiceStrategies) {
-      expect(workerChoiceStrategy.opts).toStrictEqual(
-        expect.objectContaining({
-          retries:
-            pool.info.maxSize +
-            Object.keys(workerChoiceStrategy.opts.weights).length,
-          runTime: { median: false },
-          waitTime: { median: false },
-          elu: { median: false }
+      expect(workerChoiceStrategy.opts).toStrictEqual({
+        retries:
+          pool.info.maxSize +
+          Object.keys(workerChoiceStrategy.opts.weights).length,
+        runTime: { median: false },
+        waitTime: { median: false },
+        elu: { median: false },
+        weights: expect.objectContaining({
+          0: expect.any(Number),
+          [pool.info.maxSize - 1]: expect.any(Number)
         })
-      )
+      })
     }
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
@@ -534,16 +538,18 @@ describe('Abstract pool test suite', () => {
     })
     for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
       .workerChoiceStrategies) {
-      expect(workerChoiceStrategy.opts).toStrictEqual(
-        expect.objectContaining({
-          retries:
-            pool.info.maxSize +
-            Object.keys(workerChoiceStrategy.opts.weights).length,
-          runTime: { median: true },
-          waitTime: { median: false },
-          elu: { median: true }
+      expect(workerChoiceStrategy.opts).toStrictEqual({
+        retries:
+          pool.info.maxSize +
+          Object.keys(workerChoiceStrategy.opts.weights).length,
+        runTime: { median: true },
+        waitTime: { median: false },
+        elu: { median: true },
+        weights: expect.objectContaining({
+          0: expect.any(Number),
+          [pool.info.maxSize - 1]: expect.any(Number)
         })
-      )
+      })
     }
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
@@ -586,16 +592,18 @@ describe('Abstract pool test suite', () => {
     })
     for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
       .workerChoiceStrategies) {
-      expect(workerChoiceStrategy.opts).toStrictEqual(
-        expect.objectContaining({
-          retries:
-            pool.info.maxSize +
-            Object.keys(workerChoiceStrategy.opts.weights).length,
-          runTime: { median: false },
-          waitTime: { median: false },
-          elu: { median: false }
+      expect(workerChoiceStrategy.opts).toStrictEqual({
+        retries:
+          pool.info.maxSize +
+          Object.keys(workerChoiceStrategy.opts.weights).length,
+        runTime: { median: false },
+        waitTime: { median: false },
+        elu: { median: false },
+        weights: expect.objectContaining({
+          0: expect.any(Number),
+          [pool.info.maxSize - 1]: expect.any(Number)
         })
-      )
+      })
     }
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()