fix: properly account worker choice retries for WRR
[poolifier.git] / src / pools / selection-strategies / weighted-round-robin-worker-choice-strategy.ts
index fea72350ffafbb50b44f9a56935f17038952ef91..20e58752c7f5f39494b76d9eb349e4d09755adc8 100644 (file)
@@ -34,10 +34,6 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
     elu: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS
   }
 
-  /**
-   * Default worker weight.
-   */
-  private readonly defaultWorkerWeight: number
   /**
    * Worker node virtual task runtime.
    */
@@ -49,8 +45,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
     opts: InternalWorkerChoiceStrategyOptions
   ) {
     super(pool, opts)
-    this.setTaskStatisticsRequirements(this.opts)
-    this.defaultWorkerWeight = this.computeDefaultWorkerWeight()
+    this.setOptions(this.opts)
   }
 
   /** @inheritDoc */
@@ -94,10 +89,9 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
   }
 
   private weightedRoundRobinNextWorkerNodeKey (): number | undefined {
-    const workerWeight =
-      this.opts.weights?.[
-        this.nextWorkerNodeKey ?? this.previousWorkerNodeKey
-      ] ?? this.defaultWorkerWeight
+    const workerWeight = this.opts.weights?.[
+      this.nextWorkerNodeKey ?? this.previousWorkerNodeKey
+    ] as number
     if (this.workerNodeVirtualTaskRunTime < workerWeight) {
       this.workerNodeVirtualTaskRunTime =
         this.workerNodeVirtualTaskRunTime +