From: Jérôme Benoit Date: Sat, 24 Jun 2023 18:28:27 +0000 (+0200) Subject: test: cleanup helpers X-Git-Tag: v2.6.4~39 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=2c039e4373e86714cdf27e77440b12ee8eb2e4db;p=poolifier.git test: cleanup helpers Signed-off-by: Jérôme Benoit --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 52aaa398..23bb6216 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Ensure cluster pool destroy() gracefully shutdowns worker's server. +- Ensure pool event is emitted before task error promise rejection. + ## [2.6.3] - 2023-06-19 ### Fixed diff --git a/package.json b/package.json index 6867ec5f..589f12bd 100644 --- a/package.json +++ b/package.json @@ -100,8 +100,8 @@ "lib" ], "devDependencies": { - "@commitlint/cli": "^17.6.5", - "@commitlint/config-conventional": "^17.6.5", + "@commitlint/cli": "^17.6.6", + "@commitlint/config-conventional": "^17.6.6", "@release-it/bumper": "^4.0.2", "@release-it/keep-a-changelog": "^3.1.0", "@rollup/plugin-terser": "^0.4.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d38ffd0f..c260f709 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,11 +6,11 @@ settings: devDependencies: '@commitlint/cli': - specifier: ^17.6.5 - version: 17.6.5 + specifier: ^17.6.6 + version: 17.6.6 '@commitlint/config-conventional': - specifier: ^17.6.5 - version: 17.6.5 + specifier: ^17.6.6 + version: 17.6.6 '@release-it/bumper': specifier: ^4.0.2 version: 4.0.2(release-it@15.11.0) @@ -179,13 +179,13 @@ packages: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} dev: true - /@commitlint/cli@17.6.5: - resolution: {integrity: sha512-3PQrWr/uo6lzF5k7n5QuosCYnzaxP9qGBp3jhWP0Vmsa7XA6wrl9ccPqfQyXpSbQE3zBROVO3TDqgPKe4tfmLQ==} + /@commitlint/cli@17.6.6: + resolution: {integrity: sha512-sTKpr2i/Fjs9OmhU+beBxjPavpnLSqZaO6CzwKVq2Tc4UYVTMFgpKOslDhUBVlfAUBfjVO8ParxC/MXkIOevEA==} engines: {node: '>=v14'} hasBin: true dependencies: '@commitlint/format': 17.4.4 - '@commitlint/lint': 17.6.5 + '@commitlint/lint': 17.6.6 '@commitlint/load': 17.5.0 '@commitlint/read': 17.5.1 '@commitlint/types': 17.4.4 @@ -199,8 +199,8 @@ packages: - '@swc/wasm' dev: true - /@commitlint/config-conventional@17.6.5: - resolution: {integrity: sha512-Xl9H9KLl86NZm5CYNTNF9dcz1xelE/EbvhWIWcYxG/rn3UWYWdWmmnX2q6ZduNdLFSGbOxzUpIx61j5zxbeXxg==} + /@commitlint/config-conventional@17.6.6: + resolution: {integrity: sha512-phqPz3BDhfj49FUYuuZIuDiw+7T6gNAEy7Yew1IBHqSohVUCWOK2FXMSAExzS2/9X+ET93g0Uz83KjiHDOOFag==} engines: {node: '>=v14'} dependencies: conventional-changelog-conventionalcommits: 5.0.0 @@ -239,19 +239,19 @@ packages: chalk: 4.1.2 dev: true - /@commitlint/is-ignored@17.6.5: - resolution: {integrity: sha512-CQvAPt9gX7cuUbMrIaIMKczfWJqqr6m8IlJs0F2zYwyyMTQ87QMHIj5jJ5HhOaOkaj6dvTMVGx8Dd1I4xgUuoQ==} + /@commitlint/is-ignored@17.6.6: + resolution: {integrity: sha512-4Fw875faAKO+2nILC04yW/2Vy/wlV3BOYCSQ4CEFzriPEprc1Td2LILmqmft6PDEK5Sr14dT9tEzeaZj0V56Gg==} engines: {node: '>=v14'} dependencies: '@commitlint/types': 17.4.4 - semver: 7.5.0 + semver: 7.5.2 dev: true - /@commitlint/lint@17.6.5: - resolution: {integrity: sha512-BSJMwkE4LWXrOsiP9KoHG+/heSDfvOL/Nd16+ojTS/DX8HZr8dNl8l3TfVr/d/9maWD8fSegRGtBtsyGuugFrw==} + /@commitlint/lint@17.6.6: + resolution: {integrity: sha512-5bN+dnHcRLkTvwCHYMS7Xpbr+9uNi0Kq5NR3v4+oPNx6pYXt8ACuw9luhM/yMgHYwW0ajIR20wkPAFkZLEMGmg==} engines: {node: '>=v14'} dependencies: - '@commitlint/is-ignored': 17.6.5 + '@commitlint/is-ignored': 17.6.6 '@commitlint/parse': 17.6.5 '@commitlint/rules': 17.6.5 '@commitlint/types': 17.4.4 @@ -714,7 +714,7 @@ packages: lodash.get: 4.4.2 lodash.set: 4.3.2 release-it: 15.11.0 - semver: 7.5.2 + semver: 7.5.3 dev: true /@release-it/keep-a-changelog@3.1.0(release-it@15.11.0): @@ -933,7 +933,7 @@ packages: grapheme-splitter: 1.0.4 ignore: 5.2.4 natural-compare-lite: 1.4.0 - semver: 7.5.2 + semver: 7.5.3 tsutils: 3.21.0(typescript@5.1.3) typescript: 5.1.3 transitivePeerDependencies: @@ -1007,7 +1007,7 @@ packages: debug: 4.3.4(supports-color@8.1.1) globby: 11.1.0 is-glob: 4.0.3 - semver: 7.5.2 + semver: 7.5.3 tsutils: 3.21.0(typescript@5.1.3) typescript: 5.1.3 transitivePeerDependencies: @@ -1028,7 +1028,7 @@ packages: '@typescript-eslint/typescript-estree': 5.60.0(typescript@5.1.3) eslint: 8.43.0 eslint-scope: 5.1.1 - semver: 7.5.2 + semver: 7.5.3 transitivePeerDependencies: - supports-color - typescript @@ -1413,7 +1413,7 @@ packages: /builtins@5.0.1: resolution: {integrity: sha512-qwVpFEHNfhYJIzNRBvd2C1kyo6jz3ZSMPyyuR47OPdiKWlbYnZNyDWuyR175qDnAJLiCo5fBBqPb3RiXgWlkOQ==} dependencies: - semver: 7.5.2 + semver: 7.5.3 dev: true /bundle-name@3.0.0: @@ -1447,12 +1447,12 @@ packages: engines: {node: '>=14.16'} dev: true - /cacheable-request@10.2.11: - resolution: {integrity: sha512-kn0t0oJnlFo1Nzl/AYQzS/oByMtmaqLasFUa7MUMsiTrIHy8TxSkx2KzWCybE3Nuz1F4sJRGnLAfUGsPe47viQ==} + /cacheable-request@10.2.12: + resolution: {integrity: sha512-qtWGB5kn2OLjx47pYUkWicyOpK1vy9XZhq8yRTXOy+KAmjjESSRLx6SiExnnaGGUP1NM6/vmygMu0fGylNh9tw==} engines: {node: '>=14.16'} dependencies: '@types/http-cache-semantics': 4.0.1 - get-stream: 7.0.0 + get-stream: 6.0.1 http-cache-semantics: 4.1.1 keyv: 4.5.2 mimic-response: 4.0.0 @@ -2383,7 +2383,7 @@ packages: eslint: 8.43.0 esquery: 1.5.0 is-builtin-module: 3.2.1 - semver: 7.5.2 + semver: 7.5.3 spdx-expression-parse: 3.0.1 transitivePeerDependencies: - supports-color @@ -2403,7 +2403,7 @@ packages: is-core-module: 2.12.1 minimatch: 3.1.2 resolve: 1.22.2 - semver: 7.5.2 + semver: 7.5.3 dev: true /eslint-plugin-n@16.0.0(eslint@8.43.0): @@ -2420,7 +2420,7 @@ packages: is-core-module: 2.12.1 minimatch: 3.1.2 resolve: 1.22.2 - semver: 7.5.2 + semver: 7.5.3 dev: true /eslint-plugin-promise@6.1.1(eslint@8.43.0): @@ -2886,11 +2886,6 @@ packages: engines: {node: '>=10'} dev: true - /get-stream@7.0.0: - resolution: {integrity: sha512-ql6FW5b8tgMYvI4UaoxG3EQN3VyZ6VeQpxNBGg5BZ4xD4u+HJeprzhMMA4OCBEGQgSR+m87pstWMpiVW64W8Fw==} - engines: {node: '>=16'} - dev: true - /get-symbol-description@1.0.0: resolution: {integrity: sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw==} engines: {node: '>= 0.4'} @@ -3067,7 +3062,7 @@ packages: '@sindresorhus/is': 5.4.1 '@szmarczak/http-timer': 5.0.1 cacheable-lookup: 7.0.0 - cacheable-request: 10.2.11 + cacheable-request: 10.2.12 decompress-response: 6.0.0 form-data-encoder: 2.1.4 get-stream: 6.0.1 @@ -4217,8 +4212,8 @@ packages: brace-expansion: 2.0.1 dev: true - /minimatch@9.0.1: - resolution: {integrity: sha512-0jWhJpD/MdhPXwPuiRkCbfYfSKp2qnn2eOc279qI7f+osl/l+prKSrvhg157zSYvx/1nmgn2NqdT6k2Z7zSH9w==} + /minimatch@9.0.2: + resolution: {integrity: sha512-PZOT9g5v2ojiTL7r1xF6plNHLtOeTpSlDI007As2NlA2aYBMfVom17yqa6QzhmDP8QOhn7LjHTg7DFCVSSa6yg==} engines: {node: '>=16 || 14 >=14.17'} dependencies: brace-expansion: 2.0.1 @@ -4400,7 +4395,7 @@ packages: dependencies: hosted-git-info: 4.1.0 is-core-module: 2.12.1 - semver: 7.5.2 + semver: 7.5.3 validate-npm-package-license: 3.0.4 dev: true @@ -4692,7 +4687,7 @@ packages: got: 12.6.1 registry-auth-token: 5.0.2 registry-url: 6.0.1 - semver: 7.5.2 + semver: 7.5.3 dev: true /parent-module@1.0.1: @@ -5232,7 +5227,7 @@ packages: resolution: {integrity: sha512-0Ju4+6A8iOnpL/Thra7dZsSlOHYAHIeMxfhWQRI1/VLcT3WDBZKKtQt/QkBOsiIN9ZpuvHE6cGZ0x4glCMmfiA==} engines: {node: '>=12'} dependencies: - semver: 7.5.2 + semver: 7.5.3 dev: true /semver@5.7.1: @@ -5245,24 +5240,24 @@ packages: hasBin: true dev: true - /semver@7.5.0: - resolution: {integrity: sha512-+XC0AD/R7Q2mPSRuy2Id0+CGTZ98+8f+KvwirxOKIEyid+XSx6HbC63p+O4IndTHuX5Z+JxQ0TghCkO5Cg/2HA==} + /semver@7.5.1: + resolution: {integrity: sha512-Wvss5ivl8TMRZXXESstBA4uR5iXgEN/VC5/sOcuXdVLzcdkz4HWetIoRfG5gb5X+ij/G9rw9YoGn3QoQ8OCSpw==} engines: {node: '>=10'} hasBin: true dependencies: lru-cache: 6.0.0 dev: true - /semver@7.5.1: - resolution: {integrity: sha512-Wvss5ivl8TMRZXXESstBA4uR5iXgEN/VC5/sOcuXdVLzcdkz4HWetIoRfG5gb5X+ij/G9rw9YoGn3QoQ8OCSpw==} + /semver@7.5.2: + resolution: {integrity: sha512-SoftuTROv/cRjCze/scjGyiDtcUyxw1rgYQSZY7XTmtR5hX+dm76iDbTH8TkLPHCQmlbQVSSbNZCPM2hb0knnQ==} engines: {node: '>=10'} hasBin: true dependencies: lru-cache: 6.0.0 dev: true - /semver@7.5.2: - resolution: {integrity: sha512-SoftuTROv/cRjCze/scjGyiDtcUyxw1rgYQSZY7XTmtR5hX+dm76iDbTH8TkLPHCQmlbQVSSbNZCPM2hb0knnQ==} + /semver@7.5.3: + resolution: {integrity: sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==} engines: {node: '>=10'} hasBin: true dependencies: @@ -5869,7 +5864,7 @@ packages: dependencies: lunr: 2.3.9 marked: 4.3.0 - minimatch: 9.0.1 + minimatch: 9.0.2 shiki: 0.14.2 typescript: 5.1.3 dev: true @@ -5930,7 +5925,7 @@ packages: is-yarn-global: 0.4.1 latest-version: 7.0.0 pupa: 3.1.0 - semver: 7.5.2 + semver: 7.5.3 semver-diff: 4.0.0 xdg-basedir: 5.1.0 dev: true diff --git a/tests/pools/cluster/dynamic.test.js b/tests/pools/cluster/dynamic.test.js index a5250e53..f67ee01f 100644 --- a/tests/pools/cluster/dynamic.test.js +++ b/tests/pools/cluster/dynamic.test.js @@ -37,7 +37,11 @@ describe('Dynamic cluster pool test suite', () => { // The `busy` event is triggered when the number of submitted tasks at once reach the max number of workers in the dynamic pool. // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool. expect(poolBusy).toBe(max + 1) - const numberOfExitEvents = await TestUtils.waitWorkerExits(pool, max - min) + const numberOfExitEvents = await TestUtils.waitWorkerEvents( + pool, + 'exit', + max - min + ) expect(numberOfExitEvents).toBe(max - min) }) @@ -47,18 +51,18 @@ describe('Dynamic cluster pool test suite', () => { pool.execute() } expect(pool.workerNodes.length).toBeGreaterThan(min) - await TestUtils.waitWorkerExits(pool, max - min) + await TestUtils.waitWorkerEvents(pool, 'exit', max - min) expect(pool.workerNodes.length).toBe(min) for (let i = 0; i < max * 2; i++) { pool.execute() } expect(pool.workerNodes.length).toBeGreaterThan(min) - await TestUtils.waitWorkerExits(pool, max - min) + await TestUtils.waitWorkerEvents(pool, 'exit', max - min) expect(pool.workerNodes.length).toBe(min) }) it('Shutdown test', async () => { - const exitPromise = TestUtils.waitWorkerExits(pool, min) + const exitPromise = TestUtils.waitWorkerEvents(pool, 'exit', min) await pool.destroy() const numberOfExitEvents = await exitPromise expect(numberOfExitEvents).toBe(min) @@ -98,7 +102,7 @@ describe('Dynamic cluster pool test suite', () => { longRunningPool.execute() } expect(longRunningPool.workerNodes.length).toBe(max) - await TestUtils.waitWorkerExits(longRunningPool, max - min) + await TestUtils.waitWorkerEvents(longRunningPool, 'exit', max - min) expect(longRunningPool.workerNodes.length).toBe(min) expect( longRunningPool.workerChoiceStrategyContext.workerChoiceStrategies.get( diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index d1f24af4..cf0be68d 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -193,7 +193,11 @@ describe('Fixed cluster pool test suite', () => { }) it('Shutdown test', async () => { - const exitPromise = TestUtils.waitWorkerExits(pool, numberOfWorkers) + const exitPromise = TestUtils.waitWorkerEvents( + pool, + 'exit', + numberOfWorkers + ) await pool.destroy() const numberOfExitEvents = await exitPromise expect(numberOfExitEvents).toBe(numberOfWorkers) diff --git a/tests/pools/thread/dynamic.test.js b/tests/pools/thread/dynamic.test.js index 1f2a66f2..d41fa828 100644 --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.js @@ -37,7 +37,11 @@ describe('Dynamic thread pool test suite', () => { // The `busy` event is triggered when the number of submitted tasks at once reach the max number of workers in the dynamic pool. // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool. expect(poolBusy).toBe(max + 1) - const numberOfExitEvents = await TestUtils.waitWorkerExits(pool, max - min) + const numberOfExitEvents = await TestUtils.waitWorkerEvents( + pool, + 'exit', + max - min + ) expect(numberOfExitEvents).toBe(max - min) }) @@ -47,18 +51,18 @@ describe('Dynamic thread pool test suite', () => { pool.execute() } expect(pool.workerNodes.length).toBe(max) - await TestUtils.waitWorkerExits(pool, max - min) + await TestUtils.waitWorkerEvents(pool, 'exit', max - min) expect(pool.workerNodes.length).toBe(min) for (let i = 0; i < max * 2; i++) { pool.execute() } expect(pool.workerNodes.length).toBe(max) - await TestUtils.waitWorkerExits(pool, max - min) + await TestUtils.waitWorkerEvents(pool, 'exit', max - min) expect(pool.workerNodes.length).toBe(min) }) it('Shutdown test', async () => { - const exitPromise = TestUtils.waitWorkerExits(pool, min) + const exitPromise = TestUtils.waitWorkerEvents(pool, 'exit', min) await pool.destroy() const numberOfExitEvents = await exitPromise expect(numberOfExitEvents).toBe(min) @@ -98,7 +102,7 @@ describe('Dynamic thread pool test suite', () => { longRunningPool.execute() } expect(longRunningPool.workerNodes.length).toBe(max) - await TestUtils.waitWorkerExits(longRunningPool, max - min) + await TestUtils.waitWorkerEvents(longRunningPool, 'exit', max - min) expect(longRunningPool.workerNodes.length).toBe(min) expect( longRunningPool.workerChoiceStrategyContext.workerChoiceStrategies.get( diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index ab4e80b4..39ddc67d 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -197,7 +197,11 @@ describe('Fixed thread pool test suite', () => { }) it('Shutdown test', async () => { - const exitPromise = TestUtils.waitWorkerExits(pool, numberOfThreads) + const exitPromise = TestUtils.waitWorkerEvents( + pool, + 'exit', + numberOfThreads + ) await pool.destroy() const numberOfExitEvents = await exitPromise expect(numberOfExitEvents).toBe(numberOfThreads) diff --git a/tests/test-utils.js b/tests/test-utils.js index cba320a7..24b01e44 100644 --- a/tests/test-utils.js +++ b/tests/test-utils.js @@ -1,17 +1,17 @@ const { WorkerFunctions } = require('./test-types') class TestUtils { - static async waitWorkerExits (pool, numberOfExitEventsToWait) { + static async waitWorkerEvents (pool, workerEvent, numberOfEventsToWait) { return new Promise(resolve => { - let exitEvents = 0 - if (numberOfExitEventsToWait === 0) { - resolve(exitEvents) + let events = 0 + if (numberOfEventsToWait === 0) { + resolve(events) } for (const workerNode of pool.workerNodes) { - workerNode.worker.on('exit', () => { - ++exitEvents - if (exitEvents === numberOfExitEventsToWait) { - resolve(exitEvents) + workerNode.worker.on(workerEvent, () => { + ++events + if (events === numberOfEventsToWait) { + resolve(events) } }) }