From: Jérôme Benoit Date: Sat, 8 Jul 2023 21:02:45 +0000 (+0200) Subject: test: improve pool events check tests X-Git-Tag: v2.6.10~4 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=216541b6ef3426586d4c47bd52845e83bd072d15;p=poolifier.git test: improve pool events check tests Signed-off-by: Jérôme Benoit --- 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)