test: cleanup worker functions return
[poolifier.git] / tests / pools / abstract / abstract-pool.test.js
index c1e3a323997bd4623089cc4484a0680f4a659f6f..0e31ad5c21927c135ce77d1d69508c7b7061d611 100644 (file)
@@ -11,6 +11,7 @@ const {
 } = require('../../../lib')
 const { CircularArray } = require('../../../lib/circular-array')
 const { Queue } = require('../../../lib/queue')
+const { version } = require('../../../package.json')
 
 describe('Abstract pool test suite', () => {
   const numberOfWorkers = 2
@@ -393,6 +394,7 @@ describe('Abstract pool test suite', () => {
       './tests/worker-files/thread/testWorker.js'
     )
     expect(pool.info).toStrictEqual({
+      version,
       type: PoolTypes.fixed,
       worker: WorkerTypes.thread,
       minSize: numberOfWorkers,
@@ -410,9 +412,10 @@ describe('Abstract pool test suite', () => {
     pool = new DynamicClusterPool(
       numberOfWorkers,
       numberOfWorkers * 2,
-      './tests/worker-files/thread/testWorker.js'
+      './tests/worker-files/cluster/testWorker.js'
     )
     expect(pool.info).toStrictEqual({
+      version,
       type: PoolTypes.dynamic,
       worker: WorkerTypes.cluster,
       minSize: numberOfWorkers,
@@ -432,7 +435,7 @@ describe('Abstract pool test suite', () => {
   it('Simulate worker not found', async () => {
     const pool = new StubPoolWithRemoveAllWorker(
       numberOfWorkers,
-      './tests/worker-files/cluster/testWorker.js',
+      './tests/worker-files/thread/testWorker.js',
       {
         errorHandler: e => console.error(e)
       }
@@ -450,7 +453,7 @@ describe('Abstract pool test suite', () => {
       './tests/worker-files/cluster/testWorker.js'
     )
     for (const workerNode of pool.workerNodes) {
-      expect(workerNode.workerUsage).toStrictEqual({
+      expect(workerNode.usage).toStrictEqual({
         tasks: {
           executed: 0,
           executing: 0,
@@ -459,31 +462,18 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregate: 0,
-          average: 0,
-          median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregate: 0,
-          average: 0,
-          median: 0,
           history: expect.any(CircularArray)
         },
         elu: {
           idle: {
-            aggregate: 0,
-            average: 0,
-            median: 0,
             history: expect.any(CircularArray)
           },
           active: {
-            aggregate: 0,
-            average: 0,
-            median: 0,
             history: expect.any(CircularArray)
-          },
-          utilization: 0
+          }
         }
       })
     }
@@ -515,7 +505,7 @@ describe('Abstract pool test suite', () => {
       promises.add(pool.execute())
     }
     for (const workerNode of pool.workerNodes) {
-      expect(workerNode.workerUsage).toStrictEqual({
+      expect(workerNode.usage).toStrictEqual({
         tasks: {
           executed: 0,
           executing: maxMultiplier,
@@ -524,37 +514,24 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregate: 0,
-          average: 0,
-          median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregate: 0,
-          average: 0,
-          median: 0,
           history: expect.any(CircularArray)
         },
         elu: {
           idle: {
-            aggregate: 0,
-            average: 0,
-            median: 0,
             history: expect.any(CircularArray)
           },
           active: {
-            aggregate: 0,
-            average: 0,
-            median: 0,
             history: expect.any(CircularArray)
-          },
-          utilization: 0
+          }
         }
       })
     }
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
-      expect(workerNode.workerUsage).toStrictEqual({
+      expect(workerNode.usage).toStrictEqual({
         tasks: {
           executed: maxMultiplier,
           executing: 0,
@@ -563,31 +540,18 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregate: 0,
-          average: 0,
-          median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregate: 0,
-          average: 0,
-          median: 0,
           history: expect.any(CircularArray)
         },
         elu: {
           idle: {
-            aggregate: 0,
-            average: 0,
-            median: 0,
             history: expect.any(CircularArray)
           },
           active: {
-            aggregate: 0,
-            average: 0,
-            median: 0,
             history: expect.any(CircularArray)
-          },
-          utilization: 0
+          }
         }
       })
     }
@@ -607,7 +571,7 @@ describe('Abstract pool test suite', () => {
     }
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
-      expect(workerNode.workerUsage).toStrictEqual({
+      expect(workerNode.usage).toStrictEqual({
         tasks: {
           executed: expect.any(Number),
           executing: 0,
@@ -616,41 +580,26 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregate: 0,
-          average: 0,
-          median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregate: 0,
-          average: 0,
-          median: 0,
           history: expect.any(CircularArray)
         },
         elu: {
           idle: {
-            aggregate: 0,
-            average: 0,
-            median: 0,
             history: expect.any(CircularArray)
           },
           active: {
-            aggregate: 0,
-            average: 0,
-            median: 0,
             history: expect.any(CircularArray)
-          },
-          utilization: 0
+          }
         }
       })
-      expect(workerNode.workerUsage.tasks.executed).toBeGreaterThan(0)
-      expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual(
-        maxMultiplier
-      )
+      expect(workerNode.usage.tasks.executed).toBeGreaterThan(0)
+      expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(maxMultiplier)
     }
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
     for (const workerNode of pool.workerNodes) {
-      expect(workerNode.workerUsage).toStrictEqual({
+      expect(workerNode.usage).toStrictEqual({
         tasks: {
           executed: 0,
           executing: 0,
@@ -659,35 +608,22 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          aggregate: 0,
-          average: 0,
-          median: 0,
           history: expect.any(CircularArray)
         },
         waitTime: {
-          aggregate: 0,
-          average: 0,
-          median: 0,
           history: expect.any(CircularArray)
         },
         elu: {
           idle: {
-            aggregate: 0,
-            average: 0,
-            median: 0,
             history: expect.any(CircularArray)
           },
           active: {
-            aggregate: 0,
-            average: 0,
-            median: 0,
             history: expect.any(CircularArray)
-          },
-          utilization: 0
+          }
         }
       })
-      expect(workerNode.workerUsage.runTime.history.length).toBe(0)
-      expect(workerNode.workerUsage.waitTime.history.length).toBe(0)
+      expect(workerNode.usage.runTime.history.length).toBe(0)
+      expect(workerNode.usage.waitTime.history.length).toBe(0)
     }
     await pool.destroy()
   })
@@ -713,6 +649,7 @@ describe('Abstract pool test suite', () => {
     // So in total numberOfWorkers * 2 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool with min = max = numberOfWorkers.
     expect(poolFull).toBe(numberOfWorkers * 2)
     expect(poolInfo).toStrictEqual({
+      version,
       type: PoolTypes.dynamic,
       worker: WorkerTypes.thread,
       minSize: expect.any(Number),
@@ -749,6 +686,7 @@ describe('Abstract pool test suite', () => {
     // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the fixed pool.
     expect(poolBusy).toBe(numberOfWorkers + 1)
     expect(poolInfo).toStrictEqual({
+      version,
       type: PoolTypes.fixed,
       worker: WorkerTypes.thread,
       minSize: expect.any(Number),
@@ -773,12 +711,12 @@ describe('Abstract pool test suite', () => {
     )
     const data = { n: 10 }
     const result0 = await pool.execute(data)
-    expect(result0).toBe(false)
+    expect(result0).toStrictEqual({ ok: 1 })
     const result1 = await pool.execute(data, 'jsonIntegerSerialization')
-    expect(result1).toBe(false)
+    expect(result1).toStrictEqual({ ok: 1 })
     const result2 = await pool.execute(data, 'factorial')
     expect(result2).toBe(3628800)
     const result3 = await pool.execute(data, 'fibonacci')
-    expect(result3).toBe(89)
+    expect(result3).toBe(55)
   })
 })