test: cleanups
[poolifier.git] / src / pools / selection-strategies / abstract-worker-choice-strategy.ts
index 55f43092d17760653168b59bee184fc508db1d54..eaa03f3d51b44e749798f55ec54315845322c54f 100644 (file)
@@ -1,8 +1,5 @@
-import {
-  DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
-  buildWorkerChoiceStrategyOptions
-} from '../../utils.js'
 import type { IPool } from '../pool.js'
+import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../utils.js'
 import type { IWorker } from '../worker.js'
 import type {
   IWorkerChoiceStrategy,
@@ -11,6 +8,7 @@ import type {
   TaskStatisticsRequirements,
   WorkerChoiceStrategyOptions
 } from './selection-strategies-types.js'
+import { buildWorkerChoiceStrategyOptions } from './selection-strategies-utils.js'
 
 /**
  * Worker choice strategy abstract base class.
@@ -132,11 +130,14 @@ export abstract class AbstractWorkerChoiceStrategy<
   }
 
   /**
-   * Check the next worker node readiness.
+   * Check the next worker node key.
    */
-  protected checkNextWorkerNodeReadiness (): void {
-    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-    if (!this.isWorkerNodeReady(this.nextWorkerNodeKey!)) {
+  protected checkNextWorkerNodeKey (): void {
+    if (
+      this.nextWorkerNodeKey != null &&
+      (this.nextWorkerNodeKey < 0 ||
+        !this.isWorkerNodeReady(this.nextWorkerNodeKey))
+    ) {
       delete this.nextWorkerNodeKey
     }
   }
@@ -189,6 +190,9 @@ export abstract class AbstractWorkerChoiceStrategy<
    * @param workerNodeKey - The worker node key.
    */
   protected setPreviousWorkerNodeKey (workerNodeKey: number | undefined): void {
-    this.previousWorkerNodeKey = workerNodeKey ?? this.previousWorkerNodeKey
+    this.previousWorkerNodeKey =
+      workerNodeKey != null && workerNodeKey >= 0
+        ? workerNodeKey
+        : this.previousWorkerNodeKey
   }
 }