From: Jérôme Benoit Date: Sat, 19 Aug 2023 17:59:05 +0000 (+0200) Subject: test: add test for backPressure event emission X-Git-Tag: v2.6.31~21 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3e8611a873e5bc96a27b0ff0d6a54199d629384e;p=poolifier.git test: add test for backPressure event emission Signed-off-by: Jérôme Benoit --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 8adad1e4..2fcf3b22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 64e8606b..d1c58ddb 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -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() }) diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index e3ee0f65..4c2c6952 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -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) })