From 216541b6ef3426586d4c47bd52845e83bd072d15 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 8 Jul 2023 23:02:45 +0200 Subject: [PATCH] test: improve pool events check tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- tests/pools/abstract/abstract-pool.test.js | 2 +- tests/pools/cluster/fixed.test.js | 11 +++++++++-- tests/pools/thread/fixed.test.js | 11 +++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 6c340ed9..a62caad8 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -75,7 +75,7 @@ describe('Abstract pool test suite', () => { ) }) - it('Verify dynamic pool sizing', () => { + it('Verify that dynamic pool sizing is checked', () => { expect( () => new DynamicThreadPool(2, 1, './tests/worker-files/thread/testWorker.js') diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index f9423e73..6daec140 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -1,9 +1,9 @@ const { expect } = require('expect') const { FixedClusterPool, PoolEvents } = require('../../../lib') const { WorkerFunctions } = require('../../test-types') -const { waitWorkerEvents } = require('../../test-utils') +const { waitPoolEvents, waitWorkerEvents } = require('../../test-utils') -describe('Fixed cluster pool test suite', () => { +describe('Fixed cluster pool test suite', async () => { const numberOfWorkers = 6 const pool = new FixedClusterPool( numberOfWorkers, @@ -12,6 +12,9 @@ describe('Fixed cluster pool test suite', () => { errorHandler: e => console.error(e) } ) + let poolReady = 0 + pool.emitter.on(PoolEvents.ready, () => ++poolReady) + await waitPoolEvents(pool, PoolEvents.ready, 1) const queuePool = new FixedClusterPool( numberOfWorkers, './tests/worker-files/cluster/testWorker.js', @@ -77,6 +80,10 @@ describe('Fixed cluster pool test suite', () => { expect(result).toStrictEqual({ ok: 1 }) }) + it("Verify that 'ready' event is emitted", async () => { + expect(poolReady).toBe(1) + }) + it("Verify that 'busy' event is emitted", async () => { let poolBusy = 0 pool.emitter.on(PoolEvents.busy, () => ++poolBusy) diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index 829c8ade..8b2fe420 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -1,9 +1,9 @@ const { expect } = require('expect') const { FixedThreadPool, PoolEvents } = require('../../../lib') const { WorkerFunctions } = require('../../test-types') -const { waitWorkerEvents } = require('../../test-utils') +const { waitPoolEvents, waitWorkerEvents } = require('../../test-utils') -describe('Fixed thread pool test suite', () => { +describe('Fixed thread pool test suite', async () => { const numberOfThreads = 6 const pool = new FixedThreadPool( numberOfThreads, @@ -12,6 +12,9 @@ describe('Fixed thread pool test suite', () => { errorHandler: e => console.error(e) } ) + let poolReady = 0 + pool.emitter.on(PoolEvents.ready, () => ++poolReady) + await waitPoolEvents(pool, PoolEvents.ready, 1) const queuePool = new FixedThreadPool( numberOfThreads, './tests/worker-files/thread/testWorker.js', @@ -77,6 +80,10 @@ describe('Fixed thread pool test suite', () => { expect(result).toStrictEqual({ ok: 1 }) }) + it("Verify that 'ready' event is emitted", async () => { + expect(poolReady).toBe(1) + }) + it("Verify that 'busy' event is emitted", async () => { let poolBusy = 0 pool.emitter.on(PoolEvents.busy, () => ++poolBusy) -- 2.34.1