Stricter tests expectations
[poolifier.git] / tests / pools / thread / dynamic.test.js
index 94320429ce6d2cfa9deb956bcfac39f996ab26b9..5a85f6ae71cdd737b25dae925c813934da19330c 100644 (file)
@@ -1,5 +1,6 @@
 const { expect } = require('expect')
 const { DynamicThreadPool } = require('../../../lib/index')
+const WorkerFunctions = require('../../test-types')
 const TestUtils = require('../../test-utils')
 const min = 1
 const max = 3
@@ -14,9 +15,14 @@ const pool = new DynamicThreadPool(
 
 describe('Dynamic thread pool test suite', () => {
   it('Verify that the function is executed in a worker thread', async () => {
-    const result = await pool.execute({ test: 'test' })
-    expect(result).toBeDefined()
-    expect(result).toBeFalsy()
+    let result = await pool.execute({
+      function: WorkerFunctions.fibonacci
+    })
+    expect(result).toBe(false)
+    result = await pool.execute({
+      function: WorkerFunctions.factorial
+    })
+    expect(result).toBe(false)
   })
 
   it('Verify that new workers are created when required, max size is not exceeded and that after a while new workers will die', async () => {
@@ -24,7 +30,7 @@ describe('Dynamic thread pool test suite', () => {
     let poolBusy = 0
     pool.emitter.on('busy', () => poolBusy++)
     for (let i = 0; i < max * 2; i++) {
-      promises.push(pool.execute({ test: 'test' }))
+      promises.push(pool.execute())
     }
     expect(pool.workers.length).toBeLessThanOrEqual(max)
     expect(pool.workers.length).toBeGreaterThan(min)
@@ -38,13 +44,13 @@ describe('Dynamic thread pool test suite', () => {
   it('Verify scale thread up and down is working', async () => {
     expect(pool.workers.length).toBe(min)
     for (let i = 0; i < max * 10; i++) {
-      pool.execute({ test: 'test' })
+      pool.execute()
     }
     expect(pool.workers.length).toBe(max)
     await TestUtils.waitExits(pool, max - min)
     expect(pool.workers.length).toBe(min)
     for (let i = 0; i < max * 10; i++) {
-      pool.execute({ test: 'test' })
+      pool.execute()
     }
     expect(pool.workers.length).toBe(max)
     await TestUtils.waitExits(pool, max - min)
@@ -70,9 +76,8 @@ describe('Dynamic thread pool test suite', () => {
       1,
       './tests/worker-files/thread/testWorker.js'
     )
-    const res = await pool1.execute({ test: 'test' })
-    expect(res).toBeDefined()
-    expect(res).toBeFalsy()
+    const res = await pool1.execute()
+    expect(res).toBe(false)
     // We need to clean up the resources after our test
     await pool1.destroy()
   })
@@ -90,7 +95,7 @@ describe('Dynamic thread pool test suite', () => {
     )
     expect(longRunningPool.workers.length).toBe(min)
     for (let i = 0; i < max * 10; i++) {
-      longRunningPool.execute({ test: 'test' })
+      longRunningPool.execute()
     }
     expect(longRunningPool.workers.length).toBe(max)
     await TestUtils.waitExits(longRunningPool, max - min)
@@ -112,7 +117,7 @@ describe('Dynamic thread pool test suite', () => {
     )
     expect(longRunningPool.workers.length).toBe(min)
     for (let i = 0; i < max * 10; i++) {
-      longRunningPool.execute({ test: 'test' })
+      longRunningPool.execute()
     }
     expect(longRunningPool.workers.length).toBe(max)
     await TestUtils.sleep(1500)