Bump @types/node from 14.14.31 to 14.14.32 (#258)
[poolifier.git] / tests / pools / thread / dynamic.test.js
index a7f537349ed2b9d2e0a96ece08f3c1c5e2dd4964..4e7df2297fee8902d4a2331ef33baba84b24dcc4 100644 (file)
@@ -21,13 +21,13 @@ describe('Dynamic thread pool test suite', () => {
 
   it('Verify that new workers are created when required, max size is not exceeded and that after a while new workers will die', async () => {
     const promises = []
-    let fullPool = 0
-    pool.emitter.on('FullPool', () => fullPool++)
+    let poolBusy = 0
+    pool.emitter.on('busy', () => poolBusy++)
     for (let i = 0; i < max * 2; i++) {
       promises.push(pool.execute({ test: 'test' }))
     }
     expect(pool.workers.length).toBe(max)
-    expect(fullPool > 1).toBeTruthy()
+    expect(poolBusy).toEqual(max + 1)
     const res = await TestUtils.waitExits(pool, max - min)
     expect(res).toBe(max - min)
   })
@@ -59,10 +59,8 @@ describe('Dynamic thread pool test suite', () => {
     expect(closedThreads).toBe(min)
   })
 
-  it('Validations test', () => {
-    expect(() => {
-      const pool1 = new DynamicThreadPool()
-    }).toThrowError(
+  it('Validation of inputs test', () => {
+    expect(() => new DynamicThreadPool(min)).toThrowError(
       new Error('Please specify a file with a worker implementation')
     )
   })
@@ -121,4 +119,15 @@ describe('Dynamic thread pool test suite', () => {
     // We need to clean up the resources after our test
     await longRunningPool.destroy()
   })
+
+  it('Verify that a pool with zero worker can be instantiated', async () => {
+    const pool = new DynamicThreadPool(
+      0,
+      max,
+      './tests/worker-files/thread/testWorker.js'
+    )
+    expect(pool).toBeInstanceOf(DynamicThreadPool)
+    // We need to clean up the resources after our test
+    await pool.destroy()
+  })
 })