From: Jérôme Benoit Date: Sun, 27 Aug 2023 13:43:54 +0000 (+0200) Subject: test: add missing pool destroy() calls X-Git-Tag: v2.6.37~32 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0fe39c9754981258c5330fa20fb5ad6141340b33;p=poolifier.git test: add missing pool destroy() calls 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 3b3c92c0..945ee8e7 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -1172,6 +1172,8 @@ describe('Abstract pool test suite', () => { 'factorial', 'fibonacci' ]) + await dynamicThreadPool.destroy() + await fixedClusterPool.destroy() }) it('Verify that multiple task functions worker is working', async () => { @@ -1228,5 +1230,6 @@ describe('Abstract pool test suite', () => { ).toBeGreaterThanOrEqual(0) } } + await pool.destroy() }) }) diff --git a/tests/pools/cluster/dynamic.test.js b/tests/pools/cluster/dynamic.test.js index 166b546d..44d543ec 100644 --- a/tests/pools/cluster/dynamic.test.js +++ b/tests/pools/cluster/dynamic.test.js @@ -72,15 +72,15 @@ describe('Dynamic cluster pool test suite', () => { }) it('Should work even without opts in input', async () => { - const pool1 = new DynamicClusterPool( + const pool = new DynamicClusterPool( min, max, './tests/worker-files/cluster/testWorker.js' ) - const result = await pool1.execute() + const result = await pool.execute() expect(result).toStrictEqual({ ok: 1 }) // We need to clean up the resources after our test - await pool1.destroy() + await pool.destroy() }) it('Verify scale processes up and down is working when long executing task is used:hard', async () => { diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 42e13a9a..04af6384 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -80,7 +80,7 @@ describe('Fixed cluster pool test suite', () => { }) it("Verify that 'ready' event is emitted", async () => { - const pool1 = new FixedClusterPool( + const pool = new FixedClusterPool( numberOfWorkers, './tests/worker-files/cluster/testWorker.js', { @@ -88,9 +88,10 @@ describe('Fixed cluster pool test suite', () => { } ) let poolReady = 0 - pool1.emitter.on(PoolEvents.ready, () => ++poolReady) - await waitPoolEvents(pool1, PoolEvents.ready, 1) + pool.emitter.on(PoolEvents.ready, () => ++poolReady) + await waitPoolEvents(pool, PoolEvents.ready, 1) expect(poolReady).toBe(1) + await pool.destroy() }) it("Verify that 'busy' event is emitted", async () => { @@ -251,36 +252,36 @@ describe('Fixed cluster pool test suite', () => { it('Verify that cluster pool options are checked', async () => { const workerFilePath = './tests/worker-files/cluster/testWorker.js' - let pool1 = new FixedClusterPool(numberOfWorkers, workerFilePath) - expect(pool1.opts.env).toBeUndefined() - expect(pool1.opts.settings).toBeUndefined() - await pool1.destroy() - pool1 = new FixedClusterPool(numberOfWorkers, workerFilePath, { + let pool = new FixedClusterPool(numberOfWorkers, workerFilePath) + expect(pool.opts.env).toBeUndefined() + expect(pool.opts.settings).toBeUndefined() + await pool.destroy() + pool = new FixedClusterPool(numberOfWorkers, workerFilePath, { env: { TEST: 'test' }, settings: { args: ['--use', 'http'], silent: true } }) - expect(pool1.opts.env).toStrictEqual({ TEST: 'test' }) - expect(pool1.opts.settings).toStrictEqual({ + expect(pool.opts.env).toStrictEqual({ TEST: 'test' }) + expect(pool.opts.settings).toStrictEqual({ args: ['--use', 'http'], silent: true }) - expect({ ...pool1.opts.settings, exec: workerFilePath }).toStrictEqual({ + expect({ ...pool.opts.settings, exec: workerFilePath }).toStrictEqual({ args: ['--use', 'http'], silent: true, exec: workerFilePath }) - await pool1.destroy() + await pool.destroy() }) it('Should work even without opts in input', async () => { - const pool1 = new FixedClusterPool( + const pool = new FixedClusterPool( numberOfWorkers, './tests/worker-files/cluster/testWorker.js' ) - const res = await pool1.execute() + const res = await pool.execute() expect(res).toStrictEqual({ ok: 1 }) // We need to clean up the resources after our test - await pool1.destroy() + await pool.destroy() }) it('Verify that a pool with zero worker fails', async () => { diff --git a/tests/pools/thread/dynamic.test.js b/tests/pools/thread/dynamic.test.js index ea9964ca..2f3f4510 100644 --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.js @@ -72,15 +72,15 @@ describe('Dynamic thread pool test suite', () => { }) it('Should work even without opts in input', async () => { - const pool1 = new DynamicThreadPool( + const pool = new DynamicThreadPool( min, max, './tests/worker-files/thread/testWorker.js' ) - const res = await pool1.execute() + const res = await pool.execute() expect(res).toStrictEqual({ ok: 1 }) // We need to clean up the resources after our test - await pool1.destroy() + await pool.destroy() }) it('Verify scale thread up and down is working when long executing task is used:hard', async () => { diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index f63f2265..09363b84 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -80,7 +80,7 @@ describe('Fixed thread pool test suite', () => { }) it("Verify that 'ready' event is emitted", async () => { - const pool1 = new FixedThreadPool( + const pool = new FixedThreadPool( numberOfThreads, './tests/worker-files/thread/testWorker.js', { @@ -88,9 +88,10 @@ describe('Fixed thread pool test suite', () => { } ) let poolReady = 0 - pool1.emitter.on(PoolEvents.ready, () => ++poolReady) - await waitPoolEvents(pool1, PoolEvents.ready, 1) + pool.emitter.on(PoolEvents.ready, () => ++poolReady) + await waitPoolEvents(pool, PoolEvents.ready, 1) expect(poolReady).toBe(1) + await pool.destroy() }) it("Verify that 'busy' event is emitted", async () => { @@ -281,31 +282,31 @@ describe('Fixed thread pool test suite', () => { it('Verify that thread pool options are checked', async () => { const workerFilePath = './tests/worker-files/thread/testWorker.js' - let pool1 = new FixedThreadPool(numberOfThreads, workerFilePath) - expect(pool1.opts.workerOptions).toBeUndefined() - await pool1.destroy() - pool1 = new FixedThreadPool(numberOfThreads, workerFilePath, { + let pool = new FixedThreadPool(numberOfThreads, workerFilePath) + expect(pool.opts.workerOptions).toBeUndefined() + await pool.destroy() + pool = new FixedThreadPool(numberOfThreads, workerFilePath, { workerOptions: { env: { TEST: 'test' }, name: 'test' } }) - expect(pool1.opts.workerOptions).toStrictEqual({ + expect(pool.opts.workerOptions).toStrictEqual({ env: { TEST: 'test' }, name: 'test' }) - await pool1.destroy() + await pool.destroy() }) it('Should work even without opts in input', async () => { - const pool1 = new FixedThreadPool( + const pool = new FixedThreadPool( numberOfThreads, './tests/worker-files/thread/testWorker.js' ) - const res = await pool1.execute() + const res = await pool.execute() expect(res).toStrictEqual({ ok: 1 }) // We need to clean up the resources after our test - await pool1.destroy() + await pool.destroy() }) it('Verify that a pool with zero worker fails', async () => {