test: cleanup helpers
[poolifier.git] / src / pools / selection-strategies / round-robin-worker-choice-strategy.ts
index 107e9639b38466e3d832fd217885b21b27206f12..0995b3506b102931ab59956a927a51f0aa5fbbbc 100644 (file)
@@ -4,6 +4,7 @@ import type { IWorker } from '../worker'
 import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
 import type {
   IWorkerChoiceStrategy,
+  StrategyPolicy,
   WorkerChoiceStrategyOptions
 } from './selection-strategies-types'
 
@@ -21,10 +22,10 @@ export class RoundRobinWorkerChoiceStrategy<
   >
   extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
   implements IWorkerChoiceStrategy {
-  /**
-   * Id of the next worker node.
-   */
-  private nextWorkerNodeId: number = 0
+  /** @inheritDoc */
+  public readonly strategyPolicy: StrategyPolicy = {
+    useDynamicWorker: true
+  }
 
   /** @inheritDoc */
   public constructor (
@@ -32,7 +33,7 @@ export class RoundRobinWorkerChoiceStrategy<
     opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
   ) {
     super(pool, opts)
-    this.checkOptions(opts)
+    this.setTaskStatisticsRequirements(this.opts)
   }
 
   /** @inheritDoc */
@@ -41,6 +42,11 @@ export class RoundRobinWorkerChoiceStrategy<
     return true
   }
 
+  /** @inheritDoc */
+  public update (): boolean {
+    return true
+  }
+
   /** @inheritDoc */
   public choose (): number {
     const chosenWorkerNodeKey = this.nextWorkerNodeId
@@ -56,11 +62,8 @@ export class RoundRobinWorkerChoiceStrategy<
     if (this.nextWorkerNodeId === workerNodeKey) {
       if (this.pool.workerNodes.length === 0) {
         this.nextWorkerNodeId = 0
-      } else {
-        this.nextWorkerNodeId =
-          this.nextWorkerNodeId > this.pool.workerNodes.length - 1
-            ? this.pool.workerNodes.length - 1
-            : this.nextWorkerNodeId
+      } else if (this.nextWorkerNodeId > this.pool.workerNodes.length - 1) {
+        this.nextWorkerNodeId = this.pool.workerNodes.length - 1
       }
     }
     return true