refactor: align worker choice strategy options namespace
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 9 Jun 2023 10:28:01 +0000 (12:28 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 9 Jun 2023 10:28:01 +0000 (12:28 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
16 files changed:
CHANGELOG.md
README.md
src/pools/abstract-pool.ts
src/pools/selection-strategies/abstract-worker-choice-strategy.ts
src/pools/selection-strategies/fair-share-worker-choice-strategy.ts
src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts
src/pools/selection-strategies/least-busy-worker-choice-strategy.ts
src/pools/selection-strategies/least-used-worker-choice-strategy.ts
src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
src/pools/selection-strategies/selection-strategies-types.ts
src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts
src/pools/worker.ts
src/utils.ts
tests/pools/abstract/abstract-pool.test.js
tests/pools/selection-strategies/selection-strategies.test.js
tests/pools/selection-strategies/worker-choice-strategy-context.test.js

index 01c1dab45f43214835436d40ea9eb887e000686e..66762b0d7f295c7bc59da094d142771a027f984f 100644 (file)
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Changed
 
 - Refactor pool worker node usage internals.
+- Refactor worker choice strategy statistics requirements.
 
 ### Fixed
 
index 5383863d23741c7d74c4eb585c05a75556be2db6..ca6d7aff2bd0581808bd8eb54fc1a400d101f9ec 100644 (file)
--- a/README.md
+++ b/README.md
@@ -173,10 +173,11 @@ An object with these properties:
 - `workerChoiceStrategyOptions` (optional) - The worker choice strategy options object to use in this pool.  
   Properties:
 
-  - `medRunTime` (optional) - Use the tasks median runtime instead of the tasks average runtime in worker choice strategies.
+  - `runTime` (optional) - Use the tasks median runtime instead of the tasks average runtime in worker choice strategies.
+  - `waitTime` (optional) - Use the tasks median wait time instead of the tasks average wait time in worker choice strategies.
   - `weights` (optional) - The worker weights to use in the weighted round robin worker choice strategy: `{ 0: 200, 1: 300, ..., n: 100 }`
 
-  Default: `{ medRunTime: false }`
+  Default: `{ runTime: { median: false }, waitTime: { median: false } }`
 
 - `restartWorkerOnError` (optional) - Restart worker on uncaught error in this pool.  
   Default: `true`
index ca660951932fcf24219b98a5ba996f524085e0c5..3c690fb819e9c718163e86badcde28786a5dd849 100644 (file)
@@ -502,19 +502,20 @@ export abstract class AbstractPool<
   ): void {
     if (
       this.workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime
+        .aggregate
     ) {
-      workerUsage.runTime.aggregation += message.taskPerformance?.runTime ?? 0
+      workerUsage.runTime.aggregate += message.taskPerformance?.runTime ?? 0
       if (
-        this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
-          .avgRunTime &&
+        this.workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime
+          .average &&
         workerUsage.tasks.executed !== 0
       ) {
         workerUsage.runTime.average =
-          workerUsage.runTime.aggregation / workerUsage.tasks.executed
+          workerUsage.runTime.aggregate / workerUsage.tasks.executed
       }
       if (
-        this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
-          .medRunTime &&
+        this.workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime
+          .median &&
         message.taskPerformance?.runTime != null
       ) {
         workerUsage.runTime.history.push(message.taskPerformance.runTime)
@@ -531,19 +532,20 @@ export abstract class AbstractPool<
     const taskWaitTime = timestamp - (task.timestamp ?? timestamp)
     if (
       this.workerChoiceStrategyContext.getTaskStatisticsRequirements().waitTime
+        .aggregate
     ) {
-      workerUsage.waitTime.aggregation += taskWaitTime ?? 0
+      workerUsage.waitTime.aggregate += taskWaitTime ?? 0
       if (
         this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
-          .avgWaitTime &&
+          .waitTime.average &&
         workerUsage.tasks.executed !== 0
       ) {
         workerUsage.waitTime.average =
-          workerUsage.waitTime.aggregation / workerUsage.tasks.executed
+          workerUsage.waitTime.aggregate / workerUsage.tasks.executed
       }
       if (
         this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
-          .medWaitTime &&
+          .waitTime.median &&
         taskWaitTime != null
       ) {
         workerUsage.waitTime.history.push(taskWaitTime)
@@ -825,7 +827,7 @@ export abstract class AbstractPool<
       statistics: {
         runTime:
           this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
-            .runTime,
+            .runTime.aggregate,
         elu: this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
           .elu
       }
@@ -836,13 +838,13 @@ export abstract class AbstractPool<
     return {
       tasks: this.getTaskStatistics(worker),
       runTime: {
-        aggregation: 0,
+        aggregate: 0,
         average: 0,
         median: 0,
         history: new CircularArray()
       },
       waitTime: {
-        aggregation: 0,
+        aggregate: 0,
         average: 0,
         median: 0,
         history: new CircularArray()
index 41573ab43dcafe60560b25924fbf1adb94901970..18b47a1d9d38bcbb1ac4361dd4938d0106d47fe7 100644 (file)
@@ -26,12 +26,16 @@ export abstract class AbstractWorkerChoiceStrategy<
   private toggleFindLastFreeWorkerNodeKey: boolean = false
   /** @inheritDoc */
   public readonly taskStatisticsRequirements: TaskStatisticsRequirements = {
-    runTime: false,
-    avgRunTime: false,
-    medRunTime: false,
-    waitTime: false,
-    avgWaitTime: false,
-    medWaitTime: false,
+    runTime: {
+      aggregate: false,
+      average: false,
+      median: false
+    },
+    waitTime: {
+      aggregate: false,
+      average: false,
+      median: false
+    },
     elu: false
   }
 
@@ -48,34 +52,40 @@ export abstract class AbstractWorkerChoiceStrategy<
     this.choose = this.choose.bind(this)
   }
 
-  protected setTaskStatistics (opts: WorkerChoiceStrategyOptions): void {
+  protected setTaskStatisticsRequirements (
+    opts: WorkerChoiceStrategyOptions
+  ): void {
     if (
-      this.taskStatisticsRequirements.avgRunTime &&
-      opts.medRunTime === true
+      this.taskStatisticsRequirements.runTime.average &&
+      opts.runTime?.median === true
     ) {
-      this.taskStatisticsRequirements.avgRunTime = false
-      this.taskStatisticsRequirements.medRunTime = opts.medRunTime as boolean
+      this.taskStatisticsRequirements.runTime.average = false
+      this.taskStatisticsRequirements.runTime.median = opts.runTime
+        .median as boolean
     }
     if (
-      this.taskStatisticsRequirements.medRunTime &&
-      opts.medRunTime === false
+      this.taskStatisticsRequirements.runTime.median &&
+      opts.runTime?.median === false
     ) {
-      this.taskStatisticsRequirements.avgRunTime = true
-      this.taskStatisticsRequirements.medRunTime = opts.medRunTime as boolean
+      this.taskStatisticsRequirements.runTime.average = true
+      this.taskStatisticsRequirements.runTime.median = opts.runTime
+        .median as boolean
     }
     if (
-      this.taskStatisticsRequirements.avgWaitTime &&
-      opts.medWaitTime === true
+      this.taskStatisticsRequirements.waitTime.average &&
+      opts.waitTime?.median === true
     ) {
-      this.taskStatisticsRequirements.avgWaitTime = false
-      this.taskStatisticsRequirements.medWaitTime = opts.medWaitTime as boolean
+      this.taskStatisticsRequirements.waitTime.average = false
+      this.taskStatisticsRequirements.waitTime.median = opts.waitTime
+        .median as boolean
     }
     if (
-      this.taskStatisticsRequirements.medWaitTime &&
-      opts.medWaitTime === false
+      this.taskStatisticsRequirements.waitTime.median &&
+      opts.waitTime?.median === false
     ) {
-      this.taskStatisticsRequirements.avgWaitTime = true
-      this.taskStatisticsRequirements.medWaitTime = opts.medWaitTime as boolean
+      this.taskStatisticsRequirements.waitTime.average = true
+      this.taskStatisticsRequirements.waitTime.median = opts.waitTime
+        .median as boolean
     }
   }
 
@@ -94,7 +104,7 @@ export abstract class AbstractWorkerChoiceStrategy<
   /** @inheritDoc */
   public setOptions (opts: WorkerChoiceStrategyOptions): void {
     opts = opts ?? DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
-    this.setTaskStatistics(opts)
+    this.setTaskStatisticsRequirements(opts)
     this.opts = opts
   }
 
@@ -114,28 +124,28 @@ export abstract class AbstractWorkerChoiceStrategy<
 
   /**
    * Gets the worker task runtime.
-   * If the task statistics require `avgRunTime`, the average runtime is returned.
-   * If the task statistics require `medRunTime`, the median runtime is returned.
+   * If the task statistics require the average runtime, the average runtime is returned.
+   * If the task statistics require the median runtime , the median runtime is returned.
    *
    * @param workerNodeKey - The worker node key.
    * @returns The worker task runtime.
    */
   protected getWorkerTaskRunTime (workerNodeKey: number): number {
-    return this.taskStatisticsRequirements.medRunTime
+    return this.taskStatisticsRequirements.runTime.median
       ? this.pool.workerNodes[workerNodeKey].workerUsage.runTime.median
       : this.pool.workerNodes[workerNodeKey].workerUsage.runTime.average
   }
 
   /**
    * Gets the worker task wait time.
-   * If the task statistics require `avgWaitTime`, the average wait time is returned.
-   * If the task statistics require `medWaitTime`, the median wait time is returned.
+   * If the task statistics require the average wait time, the average wait time is returned.
+   * If the task statistics require the median wait time, the median wait time is returned.
    *
    * @param workerNodeKey - The worker node key.
    * @returns The worker task wait time.
    */
   protected getWorkerWaitTime (workerNodeKey: number): number {
-    return this.taskStatisticsRequirements.medWaitTime
+    return this.taskStatisticsRequirements.waitTime.median
       ? this.pool.workerNodes[workerNodeKey].workerUsage.runTime.median
       : this.pool.workerNodes[workerNodeKey].workerUsage.runTime.average
   }
index 4462f6dd509f0519d7ebe971749aba76df9d251d..4ea68d40cd127632de1fed3b94568aa531ebe8cb 100644 (file)
@@ -25,12 +25,16 @@ export class FairShareWorkerChoiceStrategy<
   implements IWorkerChoiceStrategy {
   /** @inheritDoc */
   public readonly taskStatisticsRequirements: TaskStatisticsRequirements = {
-    runTime: true,
-    avgRunTime: true,
-    medRunTime: false,
-    waitTime: false,
-    avgWaitTime: false,
-    medWaitTime: false,
+    runTime: {
+      aggregate: true,
+      average: true,
+      median: false
+    },
+    waitTime: {
+      aggregate: false,
+      average: false,
+      median: false
+    },
     elu: false
   }
 
@@ -45,7 +49,7 @@ export class FairShareWorkerChoiceStrategy<
     opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
   ) {
     super(pool, opts)
-    this.setTaskStatistics(this.opts)
+    this.setTaskStatisticsRequirements(this.opts)
   }
 
   /** @inheritDoc */
index d7d78953036f163ad0b02d4fb06910213e226e31..7d77a21db5340bcd68a72e731f07ef01de76898b 100644 (file)
@@ -45,7 +45,7 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
     opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
   ) {
     super(pool, opts)
-    this.setTaskStatistics(this.opts)
+    this.setTaskStatisticsRequirements(this.opts)
     this.defaultWorkerWeight = this.computeDefaultWorkerWeight()
     this.roundWeights = this.getRoundWeights()
   }
index 3c0856856189ab7d7af4c4f2a625ae9058ac9029..8afd2c36edda1bcb7fe94dcb2b6d1f51c36eac9e 100644 (file)
@@ -24,12 +24,16 @@ export class LeastBusyWorkerChoiceStrategy<
   implements IWorkerChoiceStrategy {
   /** @inheritDoc */
   public readonly taskStatisticsRequirements: TaskStatisticsRequirements = {
-    runTime: true,
-    avgRunTime: false,
-    medRunTime: false,
-    waitTime: true,
-    avgWaitTime: false,
-    medWaitTime: false,
+    runTime: {
+      aggregate: true,
+      average: false,
+      median: false
+    },
+    waitTime: {
+      aggregate: true,
+      average: false,
+      median: false
+    },
     elu: false
   }
 
@@ -39,7 +43,7 @@ export class LeastBusyWorkerChoiceStrategy<
     opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
   ) {
     super(pool, opts)
-    this.setTaskStatistics(this.opts)
+    this.setTaskStatisticsRequirements(this.opts)
   }
 
   /** @inheritDoc */
@@ -58,8 +62,8 @@ export class LeastBusyWorkerChoiceStrategy<
     let leastBusyWorkerNodeKey!: number
     for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
       const workerTime =
-        workerNode.workerUsage.runTime.aggregation +
-        workerNode.workerUsage.waitTime.aggregation
+        workerNode.workerUsage.runTime.aggregate +
+        workerNode.workerUsage.waitTime.aggregate
       if (workerTime === 0) {
         return workerNodeKey
       } else if (workerTime < minTime) {
index 528bca1dc683adf0ac25cdd8f53ba4a2737b2294..4161a1d266634518c5800d57a421acb46b690fe6 100644 (file)
@@ -27,7 +27,7 @@ export class LeastUsedWorkerChoiceStrategy<
     opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
   ) {
     super(pool, opts)
-    this.setTaskStatistics(this.opts)
+    this.setTaskStatisticsRequirements(this.opts)
   }
 
   /** @inheritDoc */
index afdff788bf69eb999c2c4cc4ec08a59692c28fce..ea174552685de1ba859a879b893061fe91798de5 100644 (file)
@@ -32,7 +32,7 @@ export class RoundRobinWorkerChoiceStrategy<
     opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
   ) {
     super(pool, opts)
-    this.setTaskStatistics(this.opts)
+    this.setTaskStatisticsRequirements(this.opts)
   }
 
   /** @inheritDoc */
index 5723bd67da6af4b765bcb0e163e48643d48a72e7..26fe436d7a8e587b651458e8359a0b4d0a2e27f9 100644 (file)
@@ -35,22 +35,32 @@ export const WorkerChoiceStrategies = Object.freeze({
  */
 export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies
 
+/**
+ * Measurement options.
+ */
+interface MeasurementOptions {
+  /**
+   * Set measurement median.
+   */
+  median: boolean
+}
+
 /**
  * Worker choice strategy options.
  */
 export interface WorkerChoiceStrategyOptions {
   /**
-   * Use tasks median runtime instead of average runtime.
+   * Runtime options.
    *
-   * @defaultValue false
+   * @defaultValue \{ median: false \}
    */
-  medRunTime?: boolean
+  runTime?: MeasurementOptions
   /**
-   * Use tasks median wait time instead of average runtime.
+   * Wait time options.
    *
-   * @defaultValue false
+   * @defaultValue \{ median: false \}
    */
-  medWaitTime?: boolean
+  waitTime?: MeasurementOptions
   /**
    * Worker weights to use for weighted round robin worker selection strategy.
    * Weight is the tasks maximum average or median runtime in milliseconds.
@@ -61,35 +71,39 @@ export interface WorkerChoiceStrategyOptions {
 }
 
 /**
- * Pool worker node worker usage statistics requirements.
+ * Measurement statistics requirements.
  *
  * @internal
  */
-export interface TaskStatisticsRequirements {
-  /**
-   * Require tasks runtime.
-   */
-  runTime: boolean
+interface MeasurementStatisticsRequirements {
   /**
-   * Require tasks average runtime.
+   * Require measurement aggregate.
    */
-  avgRunTime: boolean
+  aggregate: boolean
   /**
-   * Require tasks median runtime.
+   * Require measurement average.
    */
-  medRunTime: boolean
+  average: boolean
   /**
-   * Require tasks wait time.
+   * Require measurement median.
    */
-  waitTime: boolean
+  median: boolean
+}
+
+/**
+ * Pool worker node worker usage statistics requirements.
+ *
+ * @internal
+ */
+export interface TaskStatisticsRequirements {
   /**
-   * Require tasks average wait time.
+   * Tasks runtime requirements.
    */
-  avgWaitTime: boolean
+  runTime: MeasurementStatisticsRequirements
   /**
-   * Require tasks median wait time.
+   * Tasks wait time requirements.
    */
-  medWaitTime: boolean
+  waitTime: MeasurementStatisticsRequirements
   /**
    * Event loop utilization.
    */
index 75e278bc407d704069e946be11a899cdfadaf8a7..4fcbeeda43d6021cc0d71dfb4daa66b8a046f0de 100644 (file)
@@ -25,12 +25,16 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
   implements IWorkerChoiceStrategy {
   /** @inheritDoc */
   public readonly taskStatisticsRequirements: TaskStatisticsRequirements = {
-    runTime: true,
-    avgRunTime: true,
-    medRunTime: false,
-    waitTime: false,
-    avgWaitTime: false,
-    medWaitTime: false,
+    runTime: {
+      aggregate: true,
+      average: true,
+      median: false
+    },
+    waitTime: {
+      aggregate: false,
+      average: false,
+      median: false
+    },
     elu: false
   }
 
@@ -53,7 +57,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
     opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
   ) {
     super(pool, opts)
-    this.setTaskStatistics(this.opts)
+    this.setTaskStatisticsRequirements(this.opts)
     this.defaultWorkerWeight = this.computeDefaultWorkerWeight()
   }
 
index 94f0ff73043d3d4eede636c9bcae5d0f21ee82e8..70e4a7edd0ee481a0b608bb53ae6463d3517c144 100644 (file)
@@ -63,9 +63,9 @@ export interface Task<Data = unknown> {
  */
 export interface MeasurementStatistics {
   /**
-   * Measurement aggregation.
+   * Measurement aggregate.
    */
-  aggregation: number
+  aggregate: number
   /**
    * Measurement average.
    */
index baaf1c1ca62499106a4ce0ea41148204dda75d2b..7b921ffa4b94efcfd673b75248e44ee305466058 100644 (file)
@@ -12,8 +12,8 @@ export const EMPTY_FUNCTION: () => void = Object.freeze(() => {
  */
 export const DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS: WorkerChoiceStrategyOptions =
   {
-    medRunTime: false,
-    medWaitTime: false
+    runTime: { median: false },
+    waitTime: { median: false }
   }
 
 /**
index 45371a31325e6cea532e87edd9b0c9c0fccd78dd..12237d93f7bba6c752852d7b49c72da8253a492c 100644 (file)
@@ -93,8 +93,8 @@ describe('Abstract pool test suite', () => {
       WorkerChoiceStrategies.ROUND_ROBIN
     )
     expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
-      medRunTime: false,
-      medWaitTime: false
+      runTime: { median: false },
+      waitTime: { median: false }
     })
     expect(pool.opts.messageHandler).toBeUndefined()
     expect(pool.opts.errorHandler).toBeUndefined()
@@ -108,7 +108,7 @@ describe('Abstract pool test suite', () => {
       {
         workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED,
         workerChoiceStrategyOptions: {
-          medRunTime: true,
+          runTime: { median: true },
           weights: { 0: 300, 1: 200 }
         },
         enableEvents: false,
@@ -130,7 +130,7 @@ describe('Abstract pool test suite', () => {
       WorkerChoiceStrategies.LEAST_USED
     )
     expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
-      medRunTime: true,
+      runTime: { median: true },
       weights: { 0: 300, 1: 200 }
     })
     expect(pool.opts.messageHandler).toStrictEqual(testHandler)
@@ -183,63 +183,79 @@ describe('Abstract pool test suite', () => {
       { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
     )
     expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
-      medRunTime: false,
-      medWaitTime: false
+      runTime: { median: false },
+      waitTime: { median: false }
     })
     for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
       .workerChoiceStrategies) {
       expect(workerChoiceStrategy.opts).toStrictEqual({
-        medRunTime: false,
-        medWaitTime: false
+        runTime: { median: false },
+        waitTime: { median: false }
       })
     }
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
     ).toStrictEqual({
-      runTime: true,
-      avgRunTime: true,
-      medRunTime: false,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
+      runTime: {
+        aggregate: true,
+        average: true,
+        median: false
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
       elu: false
     })
-    pool.setWorkerChoiceStrategyOptions({ medRunTime: true })
+    pool.setWorkerChoiceStrategyOptions({ runTime: { median: true } })
     expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
-      medRunTime: true
+      runTime: { median: true }
     })
     for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
       .workerChoiceStrategies) {
-      expect(workerChoiceStrategy.opts).toStrictEqual({ medRunTime: true })
+      expect(workerChoiceStrategy.opts).toStrictEqual({
+        runTime: { median: true }
+      })
     }
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
     ).toStrictEqual({
-      runTime: true,
-      avgRunTime: false,
-      medRunTime: true,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
+      runTime: {
+        aggregate: true,
+        average: false,
+        median: true
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
       elu: false
     })
-    pool.setWorkerChoiceStrategyOptions({ medRunTime: false })
+    pool.setWorkerChoiceStrategyOptions({ runTime: { median: false } })
     expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
-      medRunTime: false
+      runTime: { median: false }
     })
     for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
       .workerChoiceStrategies) {
-      expect(workerChoiceStrategy.opts).toStrictEqual({ medRunTime: false })
+      expect(workerChoiceStrategy.opts).toStrictEqual({
+        runTime: { median: false }
+      })
     }
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
     ).toStrictEqual({
-      runTime: true,
-      avgRunTime: true,
-      medRunTime: false,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
+      runTime: {
+        aggregate: true,
+        average: true,
+        median: false
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
       elu: false
     })
     await pool.destroy()
@@ -350,13 +366,13 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
@@ -399,13 +415,13 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
@@ -423,13 +439,13 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
@@ -461,13 +477,13 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
@@ -489,13 +505,13 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
index 809d5350fc28441f6ac05ccab93a052340698fe0..d43023b302f3923fc87218cbc8799721ca7026fc 100644 (file)
@@ -124,12 +124,16 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
     ).toStrictEqual({
-      runTime: false,
-      avgRunTime: false,
-      medRunTime: false,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
+      runTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
       elu: false
     })
     await pool.destroy()
@@ -142,12 +146,16 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
     ).toStrictEqual({
-      runTime: false,
-      avgRunTime: false,
-      medRunTime: false,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
+      runTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
       elu: false
     })
     // We need to clean up the resources after our test
@@ -176,13 +184,13 @@ describe('Selection strategies test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
@@ -222,13 +230,13 @@ describe('Selection strategies test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
@@ -321,12 +329,16 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
     ).toStrictEqual({
-      runTime: false,
-      avgRunTime: false,
-      medRunTime: false,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
+      runTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
       elu: false
     })
     await pool.destroy()
@@ -339,12 +351,16 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
     ).toStrictEqual({
-      runTime: false,
-      avgRunTime: false,
-      medRunTime: false,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
+      runTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
       elu: false
     })
     // We need to clean up the resources after our test
@@ -373,13 +389,13 @@ describe('Selection strategies test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
@@ -414,13 +430,13 @@ describe('Selection strategies test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
@@ -443,12 +459,16 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
     ).toStrictEqual({
-      runTime: true,
-      avgRunTime: false,
-      medRunTime: false,
-      waitTime: true,
-      avgWaitTime: false,
-      medWaitTime: false,
+      runTime: {
+        aggregate: true,
+        average: false,
+        median: false
+      },
+      waitTime: {
+        aggregate: true,
+        average: false,
+        median: false
+      },
       elu: false
     })
     await pool.destroy()
@@ -461,12 +481,16 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
     ).toStrictEqual({
-      runTime: true,
-      avgRunTime: false,
-      medRunTime: false,
-      waitTime: true,
-      avgWaitTime: false,
-      medWaitTime: false,
+      runTime: {
+        aggregate: true,
+        average: false,
+        median: false
+      },
+      waitTime: {
+        aggregate: true,
+        average: false,
+        median: false
+      },
       elu: false
     })
     // We need to clean up the resources after our test
@@ -495,13 +519,13 @@ describe('Selection strategies test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: expect.any(Number),
+          aggregate: expect.any(Number),
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: expect.any(Number),
+          aggregate: expect.any(Number),
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
@@ -512,12 +536,10 @@ describe('Selection strategies test suite', () => {
       expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual(
         max * maxMultiplier
       )
-      expect(workerNode.workerUsage.runTime.aggregation).toBeGreaterThanOrEqual(
+      expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThanOrEqual(0)
+      expect(workerNode.workerUsage.waitTime.aggregate).toBeGreaterThanOrEqual(
         0
       )
-      expect(
-        workerNode.workerUsage.waitTime.aggregation
-      ).toBeGreaterThanOrEqual(0)
     }
     // We need to clean up the resources after our test
     await pool.destroy()
@@ -546,13 +568,13 @@ describe('Selection strategies test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: expect.any(Number),
+          aggregate: expect.any(Number),
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: expect.any(Number),
+          aggregate: expect.any(Number),
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
@@ -563,8 +585,8 @@ describe('Selection strategies test suite', () => {
       expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual(
         max * maxMultiplier
       )
-      expect(workerNode.workerUsage.runTime.aggregation).toBeGreaterThan(0)
-      expect(workerNode.workerUsage.waitTime.aggregation).toBeGreaterThan(0)
+      expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThan(0)
+      expect(workerNode.workerUsage.waitTime.aggregate).toBeGreaterThan(0)
     }
     // We need to clean up the resources after our test
     await pool.destroy()
@@ -580,12 +602,16 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
     ).toStrictEqual({
-      runTime: true,
-      avgRunTime: true,
-      medRunTime: false,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
+      runTime: {
+        aggregate: true,
+        average: true,
+        median: false
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
       elu: false
     })
     await pool.destroy()
@@ -598,12 +624,16 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
     ).toStrictEqual({
-      runTime: true,
-      avgRunTime: true,
-      medRunTime: false,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
+      runTime: {
+        aggregate: true,
+        average: true,
+        median: false
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
       elu: false
     })
     // We need to clean up the resources after our test
@@ -632,20 +662,20 @@ describe('Selection strategies test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: expect.any(Number),
+          aggregate: expect.any(Number),
           average: expect.any(Number),
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         elu: undefined
       })
-      expect(workerNode.workerUsage.runTime.aggregation).toBeGreaterThan(0)
+      expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThan(0)
       expect(workerNode.workerUsage.runTime.average).toBeGreaterThan(0)
     }
     expect(
@@ -680,20 +710,20 @@ describe('Selection strategies test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: expect.any(Number),
+          aggregate: expect.any(Number),
           average: expect.any(Number),
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         elu: undefined
       })
-      expect(workerNode.workerUsage.runTime.aggregation).toBeGreaterThan(0)
+      expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThan(0)
       expect(workerNode.workerUsage.runTime.average).toBeGreaterThan(0)
     }
     expect(
@@ -713,7 +743,7 @@ describe('Selection strategies test suite', () => {
       {
         workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE,
         workerChoiceStrategyOptions: {
-          medRunTime: true
+          runTime: { median: true }
         }
       }
     )
@@ -733,20 +763,20 @@ describe('Selection strategies test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: expect.any(Number),
+          aggregate: expect.any(Number),
           average: 0,
           median: expect.any(Number),
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         elu: undefined
       })
-      expect(workerNode.workerUsage.runTime.aggregation).toBeGreaterThan(0)
+      expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThan(0)
       expect(workerNode.workerUsage.runTime.median).toBeGreaterThan(0)
     }
     expect(
@@ -842,12 +872,16 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
     ).toStrictEqual({
-      runTime: true,
-      avgRunTime: true,
-      medRunTime: false,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
+      runTime: {
+        aggregate: true,
+        average: true,
+        median: false
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
       elu: false
     })
     await pool.destroy()
@@ -860,12 +894,16 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
     ).toStrictEqual({
-      runTime: true,
-      avgRunTime: true,
-      medRunTime: false,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
+      runTime: {
+        aggregate: true,
+        average: true,
+        median: false
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
       elu: false
     })
     // We need to clean up the resources after our test
@@ -894,13 +932,13 @@ describe('Selection strategies test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: expect.any(Number),
+          aggregate: expect.any(Number),
           average: expect.any(Number),
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
@@ -911,9 +949,7 @@ describe('Selection strategies test suite', () => {
       expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual(
         max * maxMultiplier
       )
-      expect(workerNode.workerUsage.runTime.aggregation).toBeGreaterThanOrEqual(
-        0
-      )
+      expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThanOrEqual(0)
       expect(workerNode.workerUsage.runTime.average).toBeGreaterThanOrEqual(0)
     }
     expect(
@@ -953,13 +989,13 @@ describe('Selection strategies test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: expect.any(Number),
+          aggregate: expect.any(Number),
           average: expect.any(Number),
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
@@ -970,7 +1006,7 @@ describe('Selection strategies test suite', () => {
       expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual(
         max * maxMultiplier
       )
-      expect(workerNode.workerUsage.runTime.aggregation).toBeGreaterThan(0)
+      expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThan(0)
       expect(workerNode.workerUsage.runTime.average).toBeGreaterThan(0)
     }
     expect(
@@ -995,7 +1031,7 @@ describe('Selection strategies test suite', () => {
       {
         workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN,
         workerChoiceStrategyOptions: {
-          medRunTime: true
+          runTime: { median: true }
         }
       }
     )
@@ -1015,13 +1051,13 @@ describe('Selection strategies test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: expect.any(Number),
+          aggregate: expect.any(Number),
           average: 0,
           median: expect.any(Number),
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
@@ -1032,7 +1068,7 @@ describe('Selection strategies test suite', () => {
       expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual(
         max * maxMultiplier
       )
-      expect(workerNode.workerUsage.runTime.aggregation).toBeGreaterThan(0)
+      expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThan(0)
       expect(workerNode.workerUsage.runTime.median).toBeGreaterThan(0)
     }
     expect(
@@ -1138,12 +1174,16 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
     ).toStrictEqual({
-      runTime: false,
-      avgRunTime: false,
-      medRunTime: false,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
+      runTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
       elu: false
     })
     await pool.destroy()
@@ -1156,12 +1196,16 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
     ).toStrictEqual({
-      runTime: false,
-      avgRunTime: false,
-      medRunTime: false,
-      waitTime: false,
-      avgWaitTime: false,
-      medWaitTime: false,
+      runTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
+      waitTime: {
+        aggregate: false,
+        average: false,
+        median: false
+      },
       elu: false
     })
     // We need to clean up the resources after our test
@@ -1193,13 +1237,13 @@ describe('Selection strategies test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
@@ -1261,13 +1305,13 @@ describe('Selection strategies test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregation: 0,
+          aggregate: 0,
           average: 0,
           median: 0,
           history: expect.any(CircularArray)
index 2c5b7abbcc78c1429e9f23d0a8a414a659232c52..e39b1484ddb53a2a97cf22721ada61b565349fc6 100644 (file)
@@ -365,54 +365,58 @@ describe('Worker choice strategy context test suite', () => {
       fixedPool,
       wwrWorkerChoiceStrategy,
       {
-        medRunTime: true
+        runTime: { median: true }
       }
     )
     expect(
-      workerChoiceStrategyContext.getTaskStatisticsRequirements().avgRunTime
+      workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime
+        .average
     ).toBe(false)
     expect(
-      workerChoiceStrategyContext.getTaskStatisticsRequirements().medRunTime
+      workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime.median
     ).toBe(true)
     workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
       dynamicPool,
       wwrWorkerChoiceStrategy,
       {
-        medRunTime: true
+        runTime: { median: true }
       }
     )
     expect(
-      workerChoiceStrategyContext.getTaskStatisticsRequirements().avgRunTime
+      workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime
+        .average
     ).toBe(false)
     expect(
-      workerChoiceStrategyContext.getTaskStatisticsRequirements().medRunTime
+      workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime.median
     ).toBe(true)
     const fsWorkerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE
     workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
       fixedPool,
       fsWorkerChoiceStrategy,
       {
-        medRunTime: true
+        runTime: { median: true }
       }
     )
     expect(
-      workerChoiceStrategyContext.getTaskStatisticsRequirements().avgRunTime
+      workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime
+        .average
     ).toBe(false)
     expect(
-      workerChoiceStrategyContext.getTaskStatisticsRequirements().medRunTime
+      workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime.median
     ).toBe(true)
     workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
       dynamicPool,
       fsWorkerChoiceStrategy,
       {
-        medRunTime: true
+        runTime: { median: true }
       }
     )
     expect(
-      workerChoiceStrategyContext.getTaskStatisticsRequirements().avgRunTime
+      workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime
+        .average
     ).toBe(false)
     expect(
-      workerChoiceStrategyContext.getTaskStatisticsRequirements().medRunTime
+      workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime.median
     ).toBe(true)
   })
 })