docs: refine worker choice strategy documentation
[poolifier.git] / tests / pools / thread / fixed.test.js
index 7b4b9bf536acd131c3dcc1a9e729f90e86ff05e4..f2b36fa7d9eeb617919c86dcdbbf1d797f7e777e 100644 (file)
@@ -72,7 +72,7 @@ describe('Fixed thread pool test suite', () => {
     expect(result).toBe(false)
   })
 
-  it('Verify that is possible to invoke the execute method without input', async () => {
+  it('Verify that is possible to invoke the execute() method without input', async () => {
     const result = await pool.execute()
     expect(result).toBe(false)
   })
@@ -90,9 +90,11 @@ describe('Fixed thread pool test suite', () => {
 
   it('Verify that tasks queuing is working', async () => {
     const maxMultiplier = 10
+    const promises = new Set()
     for (let i = 0; i < numberOfThreads * maxMultiplier; i++) {
-      queuePool.execute()
+      promises.add(queuePool.execute())
     }
+    expect(promises.size).toBe(numberOfThreads * maxMultiplier)
     for (const workerNode of queuePool.workerNodes) {
       expect(workerNode.tasksUsage.running).toBeLessThanOrEqual(
         queuePool.opts.tasksQueueOptions.concurrency
@@ -100,17 +102,17 @@ describe('Fixed thread pool test suite', () => {
       expect(workerNode.tasksUsage.run).toBe(0)
       expect(workerNode.tasksQueue.length).toBeGreaterThan(0)
     }
-    // FIXME: wait for ongoing tasks to be executed
-    const promises = []
-    for (let i = 0; i < numberOfThreads * maxMultiplier; i++) {
-      promises.push(queuePool.execute())
-    }
+    expect(queuePool.numberOfRunningTasks).toBe(numberOfThreads)
+    expect(queuePool.numberOfQueuedTasks).toBe(
+      numberOfThreads * maxMultiplier - numberOfThreads
+    )
     await Promise.all(promises)
     for (const workerNode of queuePool.workerNodes) {
       expect(workerNode.tasksUsage.running).toBe(0)
       expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
       expect(workerNode.tasksQueue.length).toBe(0)
     }
+    promises.clear()
   })
 
   it('Verify that is possible to have a worker that return undefined', async () => {
@@ -184,6 +186,6 @@ describe('Fixed thread pool test suite', () => {
   it('Verify that a pool with zero worker fails', async () => {
     expect(
       () => new FixedThreadPool(0, './tests/worker-files/thread/testWorker.js')
-    ).toThrowError(new Error('Cannot instantiate a fixed pool with no worker'))
+    ).toThrowError('Cannot instantiate a fixed pool with no worker')
   })
 })