test: improve code coverage
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 26 Aug 2023 19:44:47 +0000 (21:44 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 26 Aug 2023 19:44:47 +0000 (21:44 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
tests/pools/abstract/abstract-pool.test.js

index 0890d564d9d673536507872c6ae5c965c592fc9f..37729cee58bfabc542629a070d5d7445a30f9bd5 100644 (file)
@@ -317,6 +317,19 @@ describe('Abstract pool test suite', () => {
         "Invalid worker choice strategy options: invalid measurement 'invalidMeasurement'"
       )
     )
+    expect(
+      () =>
+        new FixedThreadPool(
+          numberOfWorkers,
+          './tests/worker-files/thread/testWorker.js',
+          {
+            enableTasksQueue: true,
+            tasksQueueOptions: 'invalidTasksQueueOptions'
+          }
+        )
+    ).toThrowError(
+      new TypeError('Invalid tasks queue options: must be a plain object')
+    )
     expect(
       () =>
         new FixedThreadPool(
@@ -339,11 +352,13 @@ describe('Abstract pool test suite', () => {
           './tests/worker-files/thread/testWorker.js',
           {
             enableTasksQueue: true,
-            tasksQueueOptions: 'invalidTasksQueueOptions'
+            tasksQueueOptions: { concurrency: -1 }
           }
         )
     ).toThrowError(
-      new TypeError('Invalid tasks queue options: must be a plain object')
+      new RangeError(
+        'Invalid worker node tasks concurrency: -1 is a negative integer or zero'
+      )
     )
     expect(
       () =>
@@ -358,6 +373,64 @@ describe('Abstract pool test suite', () => {
     ).toThrowError(
       new TypeError('Invalid worker node tasks concurrency: must be an integer')
     )
+    expect(
+      () =>
+        new FixedThreadPool(
+          numberOfWorkers,
+          './tests/worker-files/thread/testWorker.js',
+          {
+            enableTasksQueue: true,
+            tasksQueueOptions: { queueMaxSize: 2 }
+          }
+        )
+    ).toThrowError(
+      new Error(
+        'Invalid tasks queue options: queueMaxSize is deprecated, please use size instead'
+      )
+    )
+    expect(
+      () =>
+        new FixedThreadPool(
+          numberOfWorkers,
+          './tests/worker-files/thread/testWorker.js',
+          {
+            enableTasksQueue: true,
+            tasksQueueOptions: { size: 0 }
+          }
+        )
+    ).toThrowError(
+      new RangeError(
+        'Invalid worker node tasks queue size: 0 is a negative integer or zero'
+      )
+    )
+    expect(
+      () =>
+        new FixedThreadPool(
+          numberOfWorkers,
+          './tests/worker-files/thread/testWorker.js',
+          {
+            enableTasksQueue: true,
+            tasksQueueOptions: { size: -1 }
+          }
+        )
+    ).toThrowError(
+      new RangeError(
+        'Invalid worker node tasks queue size: -1 is a negative integer or zero'
+      )
+    )
+    expect(
+      () =>
+        new FixedThreadPool(
+          numberOfWorkers,
+          './tests/worker-files/thread/testWorker.js',
+          {
+            enableTasksQueue: true,
+            tasksQueueOptions: { size: 0.2 }
+          }
+        )
+    ).toThrowError(
+      new TypeError('Invalid worker node tasks queue size: must be an integer')
+    )
   })
 
   it('Verify that pool worker choice strategy options can be set', async () => {