Merge branch 'master' into add-worker-test
[poolifier.git] / tests / pools / cluster / fixed.test.js
index 1a150dac2705bde9dc94ac351086b6ba81de83da..1cbfadf5b63ad3e029b61d47e24f6d6d9a445467 100644 (file)
@@ -1,10 +1,10 @@
 const expect = require('expect')
 const { FixedClusterPool } = require('../../../lib/index')
-const numWorkers = 10
+const numberOfWorkers = 10
 const maxTasks = 500
 const pool = new FixedClusterPool(
-  numWorkers,
-  './tests/worker/cluster/testWorker.js',
+  numberOfWorkers,
+  './tests/worker-files/cluster/testWorker.js',
   {
     errorHandler: e => console.error(e),
     onlineHandler: () => console.log('worker is online')
@@ -12,12 +12,15 @@ const pool = new FixedClusterPool(
 )
 const emptyPool = new FixedClusterPool(
   1,
-  './tests/worker/cluster/emptyWorker.js'
+  './tests/worker-files/cluster/emptyWorker.js'
+)
+const echoPool = new FixedClusterPool(
+  1,
+  './tests/worker-files/cluster/echoWorker.js'
 )
-const echoPool = new FixedClusterPool(1, './tests/worker/cluster/echoWorker.js')
 const errorPool = new FixedClusterPool(
   1,
-  './tests/worker/cluster/errorWorker.js',
+  './tests/worker-files/cluster/errorWorker.js',
   {
     errorHandler: e => console.error(e),
     onlineHandler: () => console.log('worker is online')
@@ -26,14 +29,14 @@ const errorPool = new FixedClusterPool(
 
 const asyncErrorPool = new FixedClusterPool(
   1,
-  './tests/worker/cluster/asyncErrorWorker.js',
+  './tests/worker-files/cluster/asyncErrorWorker.js',
   {
     onlineHandler: () => console.log('worker is online')
   }
 )
 const asyncPool = new FixedClusterPool(
   1,
-  './tests/worker/cluster/asyncWorker.js',
+  './tests/worker-files/cluster/asyncWorker.js',
   {
     maxTasks: maxTasks
   }
@@ -42,10 +45,10 @@ const asyncPool = new FixedClusterPool(
 describe('Fixed cluster pool test suite ', () => {
   it('Choose worker round robin test', async () => {
     const results = new Set()
-    for (let i = 0; i < numWorkers; i++) {
+    for (let i = 0; i < numberOfWorkers; i++) {
       results.add(pool.chooseWorker().id)
     }
-    expect(results.size).toBe(numWorkers)
+    expect(results.size).toBe(numberOfWorkers)
   })
 
   it('Verify that the function is executed in a worker cluster', async () => {
@@ -120,9 +123,9 @@ describe('Fixed cluster pool test suite ', () => {
         closedWorkers++
       })
     })
-    pool.destroy()
+    await pool.destroy()
     await new Promise(resolve => setTimeout(resolve, 200))
-    expect(closedWorkers).toBe(numWorkers)
+    expect(closedWorkers).toBe(numberOfWorkers)
   })
 
   it('Validations test', () => {
@@ -140,7 +143,7 @@ describe('Fixed cluster pool test suite ', () => {
   it('Should work even without opts in input', async () => {
     const pool1 = new FixedClusterPool(
       1,
-      './tests/worker/cluster/testWorker.js'
+      './tests/worker-files/cluster/testWorker.js'
     )
     const res = await pool1.execute({ test: 'test' })
     expect(res).toBeFalsy()