From: Jérôme Benoit Date: Mon, 28 Aug 2023 14:43:03 +0000 (+0200) Subject: test: refine UTs X-Git-Tag: v2.6.37~8 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=52a23942f7afed4403dd6b8088b646abca37b4b0;p=poolifier.git test: refine UTs 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 a44cdea5..ba9fc4f7 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -1252,4 +1252,20 @@ describe('Abstract pool test suite', () => { } await pool.destroy() }) + + it('Verify sendKillMessageToWorker()', async () => { + const pool = new DynamicClusterPool( + Math.floor(numberOfWorkers / 2), + numberOfWorkers, + './tests/worker-files/cluster/testWorker.js' + ) + const workerNodeKey = 0 + await expect( + pool.sendKillMessageToWorker( + workerNodeKey, + pool.workerNodes[workerNodeKey].info.id + ) + ).resolves.toBeUndefined() + await pool.destroy() + }) }) diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 675bf707..af3bc452 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -287,21 +287,16 @@ describe('Fixed cluster pool test suite', () => { it('Verify destroyWorkerNode()', async () => { const workerFilePath = './tests/worker-files/cluster/testWorker.js' const pool = new FixedClusterPool(numberOfWorkers, workerFilePath) + const workerNodeKey = 0 let disconnectEvent = 0 - pool.workerNodes[0].worker.on('disconnect', () => { + pool.workerNodes[workerNodeKey].worker.on('disconnect', () => { ++disconnectEvent }) let exitEvent = 0 - pool.workerNodes[0].worker.on('exit', () => { + pool.workerNodes[workerNodeKey].worker.on('exit', () => { ++exitEvent }) - let error - try { - await pool.destroyWorkerNode(0) - } catch (e) { - error = e - } - expect(error).toBeUndefined() + await expect(pool.destroyWorkerNode(workerNodeKey)).resolves.toBeUndefined() expect(disconnectEvent).toBe(1) expect(exitEvent).toBe(1) expect(pool.workerNodes.length).toBe(numberOfWorkers - 1) diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index ec756aa5..901c6665 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -312,17 +312,12 @@ describe('Fixed thread pool test suite', () => { it('Verify destroyWorkerNode()', async () => { const workerFilePath = './tests/worker-files/thread/testWorker.js' const pool = new FixedThreadPool(numberOfThreads, workerFilePath) + const workerNodeKey = 0 let exitEvent = 0 - pool.workerNodes[0].worker.on('exit', () => { + pool.workerNodes[workerNodeKey].worker.on('exit', () => { ++exitEvent }) - let error - try { - await pool.destroyWorkerNode(0) - } catch (e) { - error = e - } - expect(error).toBeUndefined() + await expect(pool.destroyWorkerNode(workerNodeKey)).resolves.toBeUndefined() expect(exitEvent).toBe(1) expect(pool.workerNodes.length).toBe(numberOfThreads - 1) await pool.destroy()