From: Jérôme Benoit Date: Mon, 28 Aug 2023 14:11:40 +0000 (+0200) Subject: test: add tests X-Git-Tag: v2.6.37~9 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7d27ec0dd77a2b67c9e7ab20831bc70a6051a853;hp=9274aa140e25aed36590c375f621f36edca4ca17;p=poolifier.git test: add tests Signed-off-by: Jérôme Benoit --- diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 6edfcd67..675bf707 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -276,16 +276,38 @@ describe('Fixed cluster pool test suite', () => { }) it('Should work even without opts in input', async () => { - const pool = new FixedClusterPool( - numberOfWorkers, - './tests/worker-files/cluster/testWorker.js' - ) + const workerFilePath = './tests/worker-files/cluster/testWorker.js' + const pool = new FixedClusterPool(numberOfWorkers, workerFilePath) const res = await pool.execute() expect(res).toStrictEqual({ ok: 1 }) // We need to clean up the resources after our test await pool.destroy() }) + it('Verify destroyWorkerNode()', async () => { + const workerFilePath = './tests/worker-files/cluster/testWorker.js' + const pool = new FixedClusterPool(numberOfWorkers, workerFilePath) + let disconnectEvent = 0 + pool.workerNodes[0].worker.on('disconnect', () => { + ++disconnectEvent + }) + let exitEvent = 0 + pool.workerNodes[0].worker.on('exit', () => { + ++exitEvent + }) + let error + try { + await pool.destroyWorkerNode(0) + } catch (e) { + error = e + } + expect(error).toBeUndefined() + expect(disconnectEvent).toBe(1) + expect(exitEvent).toBe(1) + expect(pool.workerNodes.length).toBe(numberOfWorkers - 1) + await pool.destroy() + }) + it('Verify that a pool with zero worker fails', async () => { expect( () => diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index 065774ec..ec756aa5 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -301,16 +301,33 @@ describe('Fixed thread pool test suite', () => { }) it('Should work even without opts in input', async () => { - const pool = new FixedThreadPool( - numberOfThreads, - './tests/worker-files/thread/testWorker.js' - ) + const workerFilePath = './tests/worker-files/thread/testWorker.js' + const pool = new FixedThreadPool(numberOfThreads, workerFilePath) const res = await pool.execute() expect(res).toStrictEqual({ ok: 1 }) // We need to clean up the resources after our test await pool.destroy() }) + it('Verify destroyWorkerNode()', async () => { + const workerFilePath = './tests/worker-files/thread/testWorker.js' + const pool = new FixedThreadPool(numberOfThreads, workerFilePath) + let exitEvent = 0 + pool.workerNodes[0].worker.on('exit', () => { + ++exitEvent + }) + let error + try { + await pool.destroyWorkerNode(0) + } catch (e) { + error = e + } + expect(error).toBeUndefined() + expect(exitEvent).toBe(1) + expect(pool.workerNodes.length).toBe(numberOfThreads - 1) + await pool.destroy() + }) + it('Verify that a pool with zero worker fails', async () => { expect( () => new FixedThreadPool(0, './tests/worker-files/thread/testWorker.js')