test: add test for backPressure event emission
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 19 Aug 2023 17:59:05 +0000 (19:59 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 19 Aug 2023 17:59:05 +0000 (19:59 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
CHANGELOG.md
tests/pools/abstract/abstract-pool.test.js
tests/pools/thread/fixed.test.js

index 8adad1e4722d49eda423b972cb0d124efe28003c..2fcf3b222d91f50c7280d99fd09ed69445b7b7e0 100644 (file)
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Fixed
 
-- Fix worker choice strategy retries mechanism on some edge cases.
+- Fix worker choice strategy retries mechanism in some edge cases.
 
 ### Changed
 
index 64e8606b12c1afdd36c40f605bf73f0ac2794e93..d1c58ddbb73658f495df83f345c013f16c631132 100644 (file)
@@ -902,7 +902,7 @@ describe('Abstract pool test suite', () => {
     await pool.destroy()
   })
 
-  it.skip("Verify that pool event emitter 'backPressure' event can register a callback", async () => {
+  it("Verify that pool event emitter 'backPressure' event can register a callback", async () => {
     const pool = new FixedThreadPool(
       numberOfWorkers,
       './tests/worker-files/thread/testWorker.js',
@@ -910,13 +910,7 @@ describe('Abstract pool test suite', () => {
         enableTasksQueue: true
       }
     )
-    for (const workerNode of pool.workerNodes) {
-      workerNode.hasBackPressure = sinon
-        .stub()
-        .onFirstCall()
-        .returns(true)
-        .returns(false)
-    }
+    sinon.stub(pool, 'hasBackPressure').returns(true)
     const promises = new Set()
     let poolBackPressure = 0
     let poolInfo
@@ -927,13 +921,11 @@ describe('Abstract pool test suite', () => {
     for (let i = 0; i < numberOfWorkers * 2; i++) {
       promises.add(pool.execute())
     }
-    // console.log(pool.info.backPressure)
     await Promise.all(promises)
-    // console.log(pool.info.backPressure)
-    expect(poolBackPressure).toBe(1)
+    expect(poolBackPressure).toBe(2)
     expect(poolInfo).toStrictEqual({
       version,
-      type: PoolTypes.dynamic,
+      type: PoolTypes.fixed,
       worker: WorkerTypes.thread,
       ready: expect.any(Boolean),
       strategy: WorkerChoiceStrategies.ROUND_ROBIN,
@@ -944,8 +936,12 @@ describe('Abstract pool test suite', () => {
       busyWorkerNodes: expect.any(Number),
       executedTasks: expect.any(Number),
       executingTasks: expect.any(Number),
+      maxQueuedTasks: expect.any(Number),
+      queuedTasks: expect.any(Number),
+      backPressure: true,
       failedTasks: expect.any(Number)
     })
+    expect(pool.hasBackPressure.called).toBe(true)
     await pool.destroy()
   })
 
index e3ee0f652dafe8a4401b95feb82f6c80c34751e6..4c2c6952944902647177af13756cec63e6f04b0f 100644 (file)
@@ -88,7 +88,7 @@ describe('Fixed thread pool test suite', () => {
     )
     let poolReady = 0
     pool1.emitter.on(PoolEvents.ready, () => ++poolReady)
-    await waitPoolEvents(pool1, 'ready', 1)
+    await waitPoolEvents(pool1, PoolEvents.ready, 1)
     expect(poolReady).toBe(1)
   })