fix: fix priority queue iterator
[poolifier.git] / tests / pools / abstract-pool.test.mjs
index 441e7ffc80eb5a8a9408ceb55664a0cc5c77a4f6..62df26e3aab52961562e9187a7aafadc6f8c27be 100644 (file)
@@ -8,7 +8,7 @@ import { fileURLToPath } from 'node:url'
 import { expect } from 'expect'
 import { restore, stub } from 'sinon'
 
-import { CircularArray } from '../../lib/circular-array.cjs'
+import { CircularBuffer } from '../../lib/circular-buffer.cjs'
 import {
   DynamicClusterPool,
   DynamicThreadPool,
@@ -20,7 +20,7 @@ import {
   WorkerTypes
 } from '../../lib/index.cjs'
 import { WorkerNode } from '../../lib/pools/worker-node.cjs'
-import { PriorityQueue } from '../../lib/priority-queue.cjs'
+import { defaultBucketSize, PriorityQueue } from '../../lib/priority-queue.cjs'
 import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs'
 import { waitPoolEvents } from '../test-utils.cjs'
 
@@ -761,17 +761,17 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          history: new CircularArray()
+          history: expect.any(CircularBuffer)
         },
         waitTime: {
-          history: new CircularArray()
+          history: expect.any(CircularBuffer)
         },
         elu: {
           idle: {
-            history: new CircularArray()
+            history: expect.any(CircularBuffer)
           },
           active: {
-            history: new CircularArray()
+            history: expect.any(CircularBuffer)
           }
         }
       })
@@ -789,7 +789,7 @@ describe('Abstract pool test suite', () => {
       expect(workerNode.tasksQueue).toBeInstanceOf(PriorityQueue)
       expect(workerNode.tasksQueue.size).toBe(0)
       expect(workerNode.tasksQueue.maxSize).toBe(0)
-      expect(workerNode.tasksQueue.bucketSize).toBe(numberOfWorkers * 2)
+      expect(workerNode.tasksQueue.bucketSize).toBe(defaultBucketSize)
     }
     await pool.destroy()
     pool = new DynamicThreadPool(
@@ -802,7 +802,7 @@ describe('Abstract pool test suite', () => {
       expect(workerNode.tasksQueue).toBeInstanceOf(PriorityQueue)
       expect(workerNode.tasksQueue.size).toBe(0)
       expect(workerNode.tasksQueue.maxSize).toBe(0)
-      expect(workerNode.tasksQueue.bucketSize).toBe(numberOfWorkers * 2)
+      expect(workerNode.tasksQueue.bucketSize).toBe(defaultBucketSize)
     }
     await pool.destroy()
   })
@@ -933,17 +933,17 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          history: expect.any(CircularArray)
+          history: expect.any(CircularBuffer)
         },
         waitTime: {
-          history: expect.any(CircularArray)
+          history: expect.any(CircularBuffer)
         },
         elu: {
           idle: {
-            history: expect.any(CircularArray)
+            history: expect.any(CircularBuffer)
           },
           active: {
-            history: expect.any(CircularArray)
+            history: expect.any(CircularBuffer)
           }
         }
       })
@@ -961,17 +961,17 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          history: expect.any(CircularArray)
+          history: expect.any(CircularBuffer)
         },
         waitTime: {
-          history: expect.any(CircularArray)
+          history: expect.any(CircularBuffer)
         },
         elu: {
           idle: {
-            history: expect.any(CircularArray)
+            history: expect.any(CircularBuffer)
           },
           active: {
-            history: expect.any(CircularArray)
+            history: expect.any(CircularBuffer)
           }
         }
       })
@@ -1003,17 +1003,17 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          history: expect.any(CircularArray)
+          history: expect.any(CircularBuffer)
         },
         waitTime: {
-          history: expect.any(CircularArray)
+          history: expect.any(CircularBuffer)
         },
         elu: {
           idle: {
-            history: expect.any(CircularArray)
+            history: expect.any(CircularBuffer)
           },
           active: {
-            history: expect.any(CircularArray)
+            history: expect.any(CircularBuffer)
           }
         }
       })
@@ -1021,10 +1021,6 @@ describe('Abstract pool test suite', () => {
       expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
         numberOfWorkers * maxMultiplier
       )
-      expect(workerNode.usage.runTime.history.length).toBe(0)
-      expect(workerNode.usage.waitTime.history.length).toBe(0)
-      expect(workerNode.usage.elu.idle.history.length).toBe(0)
-      expect(workerNode.usage.elu.active.history.length).toBe(0)
     }
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
     for (const workerNode of pool.workerNodes) {
@@ -1039,17 +1035,17 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          history: expect.any(CircularArray)
+          history: expect.any(CircularBuffer)
         },
         waitTime: {
-          history: expect.any(CircularArray)
+          history: expect.any(CircularBuffer)
         },
         elu: {
           idle: {
-            history: expect.any(CircularArray)
+            history: expect.any(CircularBuffer)
           },
           active: {
-            history: expect.any(CircularArray)
+            history: expect.any(CircularBuffer)
           }
         }
       })
@@ -1057,10 +1053,6 @@ describe('Abstract pool test suite', () => {
       expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
         numberOfWorkers * maxMultiplier
       )
-      expect(workerNode.usage.runTime.history.length).toBe(0)
-      expect(workerNode.usage.waitTime.history.length).toBe(0)
-      expect(workerNode.usage.elu.idle.history.length).toBe(0)
-      expect(workerNode.usage.elu.active.history.length).toBe(0)
     }
     await pool.destroy()
   })
@@ -1452,17 +1444,17 @@ describe('Abstract pool test suite', () => {
           failed: 0
         },
         runTime: {
-          history: new CircularArray()
+          history: expect.any(CircularBuffer)
         },
         waitTime: {
-          history: new CircularArray()
+          history: expect.any(CircularBuffer)
         },
         elu: expect.objectContaining({
           idle: expect.objectContaining({
-            history: expect.any(CircularArray)
+            history: expect.any(CircularBuffer)
           }),
           active: expect.objectContaining({
-            history: expect.any(CircularArray)
+            history: expect.any(CircularBuffer)
           })
         })
       })
@@ -1683,17 +1675,17 @@ describe('Abstract pool test suite', () => {
             stolen: 0
           },
           runTime: {
-            history: expect.any(CircularArray)
+            history: expect.any(CircularBuffer)
           },
           waitTime: {
-            history: expect.any(CircularArray)
+            history: expect.any(CircularBuffer)
           },
           elu: {
             idle: {
-              history: expect.any(CircularArray)
+              history: expect.any(CircularBuffer)
             },
             active: {
-              history: expect.any(CircularArray)
+              history: expect.any(CircularBuffer)
             }
           }
         })
@@ -1752,17 +1744,17 @@ describe('Abstract pool test suite', () => {
             stolen: 0
           },
           runTime: {
-            history: expect.any(CircularArray)
+            history: expect.any(CircularBuffer)
           },
           waitTime: {
-            history: expect.any(CircularArray)
+            history: expect.any(CircularBuffer)
           },
           elu: {
             idle: {
-              history: expect.any(CircularArray)
+              history: expect.any(CircularBuffer)
             },
             active: {
-              history: expect.any(CircularArray)
+              history: expect.any(CircularBuffer)
             }
           }
         })