test: improve UTs
[poolifier.git] / tests / pools / abstract / abstract-pool.test.js
index 945ee8e7acf6417b2e6816e87bce1dffce48265d..be745d94ce5e4b10c89012846f6f67d85899abc0 100644 (file)
@@ -53,7 +53,6 @@ describe('Abstract pool test suite', () => {
     expect(pool.starting).toBe(false)
     expect(pool.started).toBe(true)
     await pool.destroy()
-    expect(pool.started).toBe(false)
   })
 
   it('Verify that filePath is checked', () => {
@@ -154,22 +153,22 @@ describe('Abstract pool test suite', () => {
     )
     expect(
       () =>
-        new DynamicClusterPool(
-          1,
-          1,
-          './tests/worker-files/cluster/testWorker.js'
-        )
+        new DynamicThreadPool(0, 0, './tests/worker-files/thread/testWorker.js')
     ).toThrowError(
       new RangeError(
-        'Cannot instantiate a dynamic pool with a minimum pool size equal to the maximum pool size. Use a fixed pool instead'
+        'Cannot instantiate a dynamic pool with a maximum pool size equal to zero'
       )
     )
     expect(
       () =>
-        new DynamicThreadPool(0, 0, './tests/worker-files/thread/testWorker.js')
+        new DynamicClusterPool(
+          1,
+          1,
+          './tests/worker-files/cluster/testWorker.js'
+        )
     ).toThrowError(
       new RangeError(
-        'Cannot instantiate a dynamic pool with a maximum pool size equal to zero'
+        'Cannot instantiate a dynamic pool with a minimum pool size equal to the maximum pool size. Use a fixed pool instead'
       )
     )
   })
@@ -188,13 +187,13 @@ describe('Abstract pool test suite', () => {
       WorkerChoiceStrategies.ROUND_ROBIN
     )
     expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
-      choiceRetries: 6,
+      retries: 6,
       runTime: { median: false },
       waitTime: { median: false },
       elu: { median: false }
     })
     expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
-      choiceRetries: 6,
+      retries: 6,
       runTime: { median: false },
       waitTime: { median: false },
       elu: { median: false }
@@ -236,14 +235,14 @@ describe('Abstract pool test suite', () => {
       WorkerChoiceStrategies.LEAST_USED
     )
     expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
-      choiceRetries: 6,
+      retries: 6,
       runTime: { median: true },
       waitTime: { median: false },
       elu: { median: false },
       weights: { 0: 300, 1: 200 }
     })
     expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
-      choiceRetries: 6,
+      retries: 6,
       runTime: { median: true },
       waitTime: { median: false },
       elu: { median: false },
@@ -276,13 +275,13 @@ describe('Abstract pool test suite', () => {
           './tests/worker-files/thread/testWorker.js',
           {
             workerChoiceStrategyOptions: {
-              choiceRetries: 'invalidChoiceRetries'
+              retries: 'invalidChoiceRetries'
             }
           }
         )
     ).toThrowError(
       new TypeError(
-        'Invalid worker choice strategy options: choice retries must be an integer'
+        'Invalid worker choice strategy options: retries must be an integer'
       )
     )
     expect(
@@ -292,13 +291,13 @@ describe('Abstract pool test suite', () => {
           './tests/worker-files/thread/testWorker.js',
           {
             workerChoiceStrategyOptions: {
-              choiceRetries: -1
+              retries: -1
             }
           }
         )
     ).toThrowError(
       new RangeError(
-        "Invalid worker choice strategy options: choice retries '-1' must be greater or equal than zero"
+        "Invalid worker choice strategy options: retries '-1' must be greater or equal than zero"
       )
     )
     expect(
@@ -452,13 +451,13 @@ describe('Abstract pool test suite', () => {
       { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
     )
     expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
-      choiceRetries: 6,
+      retries: 6,
       runTime: { median: false },
       waitTime: { median: false },
       elu: { median: false }
     })
     expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
-      choiceRetries: 6,
+      retries: 6,
       runTime: { median: false },
       waitTime: { median: false },
       elu: { median: false }
@@ -466,7 +465,7 @@ describe('Abstract pool test suite', () => {
     for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
       .workerChoiceStrategies) {
       expect(workerChoiceStrategy.opts).toStrictEqual({
-        choiceRetries: 6,
+        retries: 6,
         runTime: { median: false },
         waitTime: { median: false },
         elu: { median: false }
@@ -496,13 +495,13 @@ describe('Abstract pool test suite', () => {
       elu: { median: true }
     })
     expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
-      choiceRetries: 6,
+      retries: 6,
       runTime: { median: true },
       waitTime: { median: false },
       elu: { median: true }
     })
     expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
-      choiceRetries: 6,
+      retries: 6,
       runTime: { median: true },
       waitTime: { median: false },
       elu: { median: true }
@@ -510,7 +509,7 @@ describe('Abstract pool test suite', () => {
     for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
       .workerChoiceStrategies) {
       expect(workerChoiceStrategy.opts).toStrictEqual({
-        choiceRetries: 6,
+        retries: 6,
         runTime: { median: true },
         waitTime: { median: false },
         elu: { median: true }
@@ -540,13 +539,13 @@ describe('Abstract pool test suite', () => {
       elu: { median: false }
     })
     expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
-      choiceRetries: 6,
+      retries: 6,
       runTime: { median: false },
       waitTime: { median: false },
       elu: { median: false }
     })
     expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
-      choiceRetries: 6,
+      retries: 6,
       runTime: { median: false },
       waitTime: { median: false },
       elu: { median: false }
@@ -554,7 +553,7 @@ describe('Abstract pool test suite', () => {
     for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
       .workerChoiceStrategies) {
       expect(workerChoiceStrategy.opts).toStrictEqual({
-        choiceRetries: 6,
+        retries: 6,
         runTime: { median: false },
         waitTime: { median: false },
         elu: { median: false }
@@ -588,18 +587,18 @@ describe('Abstract pool test suite', () => {
     )
     expect(() =>
       pool.setWorkerChoiceStrategyOptions({
-        choiceRetries: 'invalidChoiceRetries'
+        retries: 'invalidChoiceRetries'
       })
     ).toThrowError(
       new TypeError(
-        'Invalid worker choice strategy options: choice retries must be an integer'
+        'Invalid worker choice strategy options: retries must be an integer'
       )
     )
     expect(() =>
-      pool.setWorkerChoiceStrategyOptions({ choiceRetries: -1 })
+      pool.setWorkerChoiceStrategyOptions({ retries: -1 })
     ).toThrowError(
       new RangeError(
-        "Invalid worker choice strategy options: choice retries '-1' must be greater or equal than zero"
+        "Invalid worker choice strategy options: retries '-1' must be greater or equal than zero"
       )
     )
     expect(() =>
@@ -799,6 +798,7 @@ describe('Abstract pool test suite', () => {
       expect(workerNode.tasksQueue.size).toBe(0)
       expect(workerNode.tasksQueue.maxSize).toBe(0)
     }
+    await pool.destroy()
   })
 
   it('Verify that pool worker info are initialized', async () => {
@@ -828,6 +828,7 @@ describe('Abstract pool test suite', () => {
         ready: true
       })
     }
+    await pool.destroy()
   })
 
   it('Verify that pool execute() arguments are checked', async () => {