test: improve coverage
[poolifier.git] / src / pools / worker-node.ts
index f9b4016c29b078143d6f56d9acfcaf24b06e688d..ca275dedab806b9a4cc2c9c6aee5d3cf550b99f5 100644 (file)
@@ -13,6 +13,7 @@ import { Deque } from '../deque'
 import {
   type IWorker,
   type IWorkerNode,
+  type StrategyData,
   type WorkerInfo,
   type WorkerNodeEventCallback,
   type WorkerType,
@@ -35,6 +36,8 @@ implements IWorkerNode<Worker, Data> {
   /** @inheritdoc */
   public usage: WorkerUsage
   /** @inheritdoc */
+  public strategyData?: StrategyData
+  /** @inheritdoc */
   public messageChannel?: MessageChannel
   /** @inheritdoc */
   public tasksQueueBackPressureSize: number
@@ -53,19 +56,7 @@ implements IWorkerNode<Worker, Data> {
    * @param tasksQueueBackPressureSize - The tasks queue back pressure size.
    */
   constructor (worker: Worker, tasksQueueBackPressureSize: number) {
-    if (worker == null) {
-      throw new TypeError('Cannot construct a worker node without a worker')
-    }
-    if (tasksQueueBackPressureSize == null) {
-      throw new TypeError(
-        'Cannot construct a worker node without a tasks queue back pressure size'
-      )
-    }
-    if (!Number.isSafeInteger(tasksQueueBackPressureSize)) {
-      throw new TypeError(
-        'Cannot construct a worker node with a tasks queue back pressure size that is not an integer'
-      )
-    }
+    this.checkWorkerNodeArguments(worker, tasksQueueBackPressureSize)
     this.worker = worker
     this.info = this.initWorkerInfo(worker)
     this.usage = this.initWorkerUsage()
@@ -270,4 +261,28 @@ implements IWorkerNode<Worker, Data> {
       }
     }
   }
+
+  private checkWorkerNodeArguments (
+    worker: Worker,
+    tasksQueueBackPressureSize: number
+  ): void {
+    if (worker == null) {
+      throw new TypeError('Cannot construct a worker node without a worker')
+    }
+    if (tasksQueueBackPressureSize == null) {
+      throw new TypeError(
+        'Cannot construct a worker node without a tasks queue back pressure size'
+      )
+    }
+    if (!Number.isSafeInteger(tasksQueueBackPressureSize)) {
+      throw new TypeError(
+        'Cannot construct a worker node with a tasks queue back pressure size that is not an integer'
+      )
+    }
+    if (tasksQueueBackPressureSize <= 0) {
+      throw new RangeError(
+        'Cannot construct a worker node with a tasks queue back pressure size that is not a positive integer'
+      )
+    }
+  }
 }