Tests: Verify that worker pool tasks usage are reset at worker choice strategy change
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 11 Oct 2022 21:16:38 +0000 (23:16 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 11 Oct 2022 21:16:38 +0000 (23:16 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
tests/pools/abstract/abstract-pool.test.js

index 96dc9a10ad4120a97455cd11d43e9bae38790c3c..ac776174b31180669196fa5448da3f5e0786dff9 100644 (file)
@@ -232,6 +232,34 @@ describe('Abstract pool test suite', () => {
     pool.destroy()
   })
 
+  it('Verify that worker pool tasks usage are reset at worker choice strategy change', async () => {
+    const pool = new FixedThreadPool(
+      numberOfWorkers,
+      './tests/worker-files/thread/testWorker.js'
+    )
+    const promises = []
+    for (let i = 0; i < numberOfWorkers * 2; i++) {
+      promises.push(pool.execute())
+    }
+    await Promise.all(promises)
+    for (const tasksUsage of pool.workersTasksUsage.values()) {
+      expect(tasksUsage).toBeDefined()
+      expect(tasksUsage.run).toBe(numberOfWorkers * 2)
+      expect(tasksUsage.running).toBe(0)
+      expect(tasksUsage.runTime).toBeGreaterThanOrEqual(0)
+      expect(tasksUsage.avgRunTime).toBeGreaterThanOrEqual(0)
+    }
+    pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
+    for (const tasksUsage of pool.workersTasksUsage.values()) {
+      expect(tasksUsage).toBeDefined()
+      expect(tasksUsage.run).toBe(0)
+      expect(tasksUsage.running).toBe(0)
+      expect(tasksUsage.runTime).toBe(0)
+      expect(tasksUsage.avgRunTime).toBe(0)
+    }
+    pool.destroy()
+  })
+
   it("Verify that pool event emitter 'busy' event can register a callback", async () => {
     const pool = new FixedThreadPool(
       numberOfWorkers,