From 0e2503fc5e7d8b5884682734074e7ec6ef0cd52f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 21 Feb 2021 15:15:07 +0100 Subject: [PATCH] Ensure we always clean up resources in ut. (#214) 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 | 4 ++-- tests/pools/cluster/fixed.test.js | 1 - tests/pools/thread/dynamic.test.js | 6 ++++++ tests/pools/thread/fixed.test.js | 10 ++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index fe6aad35..9b32a7e0 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -23,7 +23,7 @@ describe('Abstract pool test suite', () => { errorHandler: e => console.error(e) } ) - // simulate worker not found. + // Simulate worker not found. pool.removeAllWorker() expect(() => pool.increaseWorkersTask()).toThrowError(expectedError) }) @@ -36,7 +36,7 @@ describe('Abstract pool test suite', () => { errorHandler: e => console.error(e) } ) - // simulate worker not found. + // Simulate worker not found. pool.removeAllWorker() expect(() => pool.decreaseWorkersTasks()).toThrowError(expectedError) }) diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index ef44e6f1..1137b407 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -25,7 +25,6 @@ const errorPool = new FixedClusterPool( errorHandler: e => console.error(e) } ) - const asyncErrorPool = new FixedClusterPool( 1, './tests/worker-files/cluster/asyncErrorWorker.js', diff --git a/tests/pools/thread/dynamic.test.js b/tests/pools/thread/dynamic.test.js index 3a162267..a7f53734 100644 --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.js @@ -75,6 +75,8 @@ describe('Dynamic thread pool test suite', () => { ) const res = await pool1.execute({ test: 'test' }) expect(res).toBeFalsy() + // We need to clean up the resources after our test + await pool1.destroy() }) it('Verify scale thread up and down is working when long running task is used:hard', async () => { @@ -94,6 +96,8 @@ describe('Dynamic thread pool test suite', () => { expect(longRunningPool.workers.length).toBe(max) await TestUtils.waitExits(longRunningPool, max - min) expect(longRunningPool.workers.length).toBe(min) + // We need to clean up the resources after our test + await longRunningPool.destroy() }) it('Verify scale thread up and down is working when long running task is used:soft', async () => { @@ -114,5 +118,7 @@ describe('Dynamic thread pool test suite', () => { await TestUtils.sleep(1500) // Here we expect the workers to be at the max size since that the task is still running expect(longRunningPool.workers.length).toBe(max) + // We need to clean up the resources after our test + await longRunningPool.destroy() }) }) diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index 881813c0..cea55025 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -33,6 +33,14 @@ const asyncPool = new FixedThreadPool( ) describe('Fixed thread pool test suite', () => { + after('Destroy all pools', async () => { + // We need to clean up the resources after our test + await echoPool.destroy() + await asyncPool.destroy() + await errorPool.destroy() + await emptyPool.destroy() + }) + it('Choose worker round robin test', async () => { const results = new Set() for (let i = 0; i < numberOfThreads; i++) { @@ -107,5 +115,7 @@ describe('Fixed thread pool test suite', () => { ) const res = await pool1.execute({ test: 'test' }) expect(res).toBeFalsy() + // We need to clean up the resources after our test + await pool1.destroy() }) }) -- 2.34.1