Coverage ci (#132)
[poolifier.git] / tests / pools / thread / fixed.test.js
index b0cf9e576517dfe9179747ed734f38544ea2c107..ec6a066bf8c0042cc2ff21a7e9345f87416b72a9 100644 (file)
@@ -1,6 +1,7 @@
 const expect = require('expect')
 const { FixedThreadPool } = require('../../../lib/index')
 const numThreads = 10
+const maxTasks = 400
 const pool = new FixedThreadPool(
   numThreads,
   './tests/worker/thread/testWorker.js',
@@ -19,7 +20,11 @@ const errorPool = new FixedThreadPool(
     onlineHandler: () => console.log('worker is online')
   }
 )
-const asyncPool = new FixedThreadPool(1, './tests/worker/thread/asyncWorker.js')
+const asyncPool = new FixedThreadPool(
+  1,
+  './tests/worker/thread/asyncWorker.js',
+  { maxTasks: maxTasks }
+)
 
 describe('Fixed thread pool test suite ', () => {
   it('Choose worker round robin test', async () => {
@@ -77,6 +82,11 @@ describe('Fixed thread pool test suite ', () => {
     expect(usedTime).toBeGreaterThanOrEqual(2000)
   })
 
+  it('Verify that maxTasks is set properly', async () => {
+    const worker = asyncPool.chooseWorker()
+    expect(worker.port2.getMaxListeners()).toBe(maxTasks)
+  })
+
   it('Shutdown test', async () => {
     let closedThreads = 0
     pool.workers.forEach(w => {