Update README.MD
[poolifier.git] / tests / fixed.test.js
index 3b485fbf0ffd9db7fc35539f8a52db2164377183..2ed97444bdb94a98f793f1833d027c0070f4b14b 100644 (file)
@@ -7,6 +7,7 @@ const pool = new FixedThreadPool(numThreads,
 const emptyPool = new FixedThreadPool(1, './tests/workers/emptyWorker.js')
 const echoPool = new FixedThreadPool(1, './tests/workers/echoWorker.js')
 const errorPool = new FixedThreadPool(1, './tests/workers/errorWorker.js', { errorHandler: (e) => console.error(e), onlineHandler: () => console.log('worker is online') })
+const asyncPool = new FixedThreadPool(1, './tests/workers/asyncWorker.js')
 
 describe('Fixed thread pool test suite ', () => {
   it('Choose worker round robin test', async () => {
@@ -54,6 +55,16 @@ describe('Fixed thread pool test suite ', () => {
     expect(inError.message).toBeTruthy()
   })
 
+  it('Verify that async function is working properly', async () => {
+    const data = { f: 10 }
+    const startTime = new Date().getTime()
+    const result = await asyncPool.execute(data)
+    const usedTime = new Date().getTime() - startTime
+    expect(result).toBeTruthy()
+    expect(result.f).toBe(data.f)
+    expect(usedTime).toBeGreaterThanOrEqual(2000)
+  })
+
   it('Shutdown test', async () => {
     let closedThreads = 0
     pool.workers.forEach(w => {
@@ -61,8 +72,7 @@ describe('Fixed thread pool test suite ', () => {
         closedThreads++
       })
     })
-    pool.destroy()
-    await new Promise(resolve => setTimeout(resolve, 1000))
+    await pool.destroy()
     expect(closedThreads).toBe(numThreads)
   })