test: add task stealing support
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 25 Aug 2023 15:03:32 +0000 (17:03 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 25 Aug 2023 15:03:32 +0000 (17:03 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
tests/pools/cluster/fixed.test.js

index 900f0edc9d139a5289e4b54509f80629e60802dc..85eb6a0affcd0a3c05be2b9923a438afaa8446b0 100644 (file)
@@ -4,7 +4,7 @@ const { TaskFunctions } = require('../../test-types')
 const { waitPoolEvents, waitWorkerEvents } = require('../../test-utils')
 
 describe('Fixed cluster pool test suite', () => {
-  const numberOfWorkers = 6
+  const numberOfWorkers = 8
   const tasksConcurrency = 2
   const pool = new FixedClusterPool(
     numberOfWorkers,
@@ -124,7 +124,9 @@ describe('Fixed cluster pool test suite', () => {
       expect(workerNode.usage.tasks.maxQueued).toBe(
         maxMultiplier - queuePool.opts.tasksQueueOptions.concurrency
       )
+      expect(workerNode.usage.tasks.stolen).toBe(0)
     }
+    expect(queuePool.info.executedTasks).toBe(0)
     expect(queuePool.info.executingTasks).toBe(
       numberOfWorkers * queuePool.opts.tasksQueueOptions.concurrency
     )
@@ -137,6 +139,7 @@ describe('Fixed cluster pool test suite', () => {
         (maxMultiplier - queuePool.opts.tasksQueueOptions.concurrency)
     )
     expect(queuePool.info.backPressure).toBe(false)
+    expect(queuePool.info.stolenTasks).toBe(0)
     await Promise.all(promises)
     for (const workerNode of queuePool.workerNodes) {
       expect(workerNode.usage.tasks.executing).toBeGreaterThanOrEqual(0)
@@ -148,7 +151,17 @@ describe('Fixed cluster pool test suite', () => {
       expect(workerNode.usage.tasks.maxQueued).toBe(
         maxMultiplier - queuePool.opts.tasksQueueOptions.concurrency
       )
+      expect(workerNode.usage.tasks.stolen).toBeGreaterThanOrEqual(0)
+      expect(workerNode.usage.tasks.stolen).toBeLessThanOrEqual(
+        numberOfWorkers * maxMultiplier
+      )
     }
+    expect(queuePool.info.executedTasks).toBe(numberOfWorkers * maxMultiplier)
+    expect(queuePool.info.backPressure).toBe(false)
+    expect(queuePool.info.stolenTasks).toBeGreaterThanOrEqual(0)
+    expect(queuePool.info.stolenTasks).toBeLessThanOrEqual(
+      numberOfWorkers * maxMultiplier
+    )
   })
 
   it('Verify that is possible to have a worker that return undefined', async () => {