From: Alessandro Pio Ardizio Date: Thu, 18 Feb 2021 16:03:47 +0000 (+0100) Subject: Fix EPIPE when run unit tests (#187) X-Git-Tag: v2.0.0-beta.2~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8bc7762018845abb73680eb1bbd65802b002ea08;p=poolifier.git Fix EPIPE when run unit tests (#187) * Try to remove the --exit * Revert "Fix EPIPE on shutdown" This reverts commit 4dc274761ce688172117009d1b306077d321f461. * Graceful shutdown during unit tests * Readd exit since that was not the solution * Capital letters on comments * Destroy all pools in after (#188) Co-authored-by: Shinigami --- diff --git a/package-lock.json b/package-lock.json index c7bcf203..5b1a7c64 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,19 +20,19 @@ } }, "@babel/core": { - "version": "7.12.16", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.12.16.tgz", - "integrity": "sha512-t/hHIB504wWceOeaOoONOhu+gX+hpjfeN6YRBT209X/4sibZQfSF1I0HFRRlBe97UZZosGx5XwUg1ZgNbelmNw==", + "version": "7.12.17", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.12.17.tgz", + "integrity": "sha512-V3CuX1aBywbJvV2yzJScRxeiiw0v2KZZYYE3giywxzFJL13RiyPjaaDwhDnxmgFTTS7FgvM2ijr4QmKNIu0AtQ==", "dev": true, "requires": { "@babel/code-frame": "^7.12.13", - "@babel/generator": "^7.12.15", - "@babel/helper-module-transforms": "^7.12.13", - "@babel/helpers": "^7.12.13", - "@babel/parser": "^7.12.16", + "@babel/generator": "^7.12.17", + "@babel/helper-module-transforms": "^7.12.17", + "@babel/helpers": "^7.12.17", + "@babel/parser": "^7.12.17", "@babel/template": "^7.12.13", - "@babel/traverse": "^7.12.13", - "@babel/types": "^7.12.13", + "@babel/traverse": "^7.12.17", + "@babel/types": "^7.12.17", "convert-source-map": "^1.7.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.1", @@ -52,9 +52,9 @@ } }, "@babel/parser": { - "version": "7.12.16", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.12.16.tgz", - "integrity": "sha512-c/+u9cqV6F0+4Hpq01jnJO+GLp2DdT63ppz9Xa+6cHaajM9VFzK/iDXiKK65YtpeVwu+ctfS6iqlMqRgQRzeCw==", + "version": "7.12.17", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.12.17.tgz", + "integrity": "sha512-r1yKkiUTYMQ8LiEI0UcQx5ETw5dpTLn9wijn9hk6KkTtOK95FndDN10M+8/s6k/Ymlbivw0Av9q4SlgF80PtHg==", "dev": true }, "json5": { @@ -81,12 +81,12 @@ } }, "@babel/generator": { - "version": "7.12.15", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.12.15.tgz", - "integrity": "sha512-6F2xHxBiFXWNSGb7vyCUTBF8RCLY66rS0zEPcP8t/nQyXjha5EuK4z7H5o7fWG8B4M7y6mqVWq1J+1PuwRhecQ==", + "version": "7.12.17", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.12.17.tgz", + "integrity": "sha512-DSA7ruZrY4WI8VxuS1jWSRezFnghEoYEFrZcw9BizQRmOZiUsiHl59+qEARGPqPikwA/GPTyRCi7isuCK/oyqg==", "dev": true, "requires": { - "@babel/types": "^7.12.13", + "@babel/types": "^7.12.17", "jsesc": "^2.5.1", "source-map": "^0.5.0" }, @@ -120,12 +120,12 @@ } }, "@babel/helper-member-expression-to-functions": { - "version": "7.12.16", - "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.12.16.tgz", - "integrity": "sha512-zYoZC1uvebBFmj1wFAlXwt35JLEgecefATtKp20xalwEK8vHAixLBXTGxNrVGEmTT+gzOThUgr8UEdgtalc1BQ==", + "version": "7.12.17", + "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.12.17.tgz", + "integrity": "sha512-Bzv4p3ODgS/qpBE0DiJ9qf5WxSmrQ8gVTe8ClMfwwsY2x/rhykxxy3bXzG7AGTnPB2ij37zGJ/Q/6FruxHxsxg==", "dev": true, "requires": { - "@babel/types": "^7.12.13" + "@babel/types": "^7.12.17" } }, "@babel/helper-module-imports": { @@ -138,9 +138,9 @@ } }, "@babel/helper-module-transforms": { - "version": "7.12.13", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.12.13.tgz", - "integrity": "sha512-acKF7EjqOR67ASIlDTupwkKM1eUisNAjaSduo5Cz+793ikfnpe7p4Q7B7EWU2PCoSTPWsQkR7hRUWEIZPiVLGA==", + "version": "7.12.17", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.12.17.tgz", + "integrity": "sha512-sFL+p6zOCQMm9vilo06M4VHuTxUAwa6IxgL56Tq1DVtA0ziAGTH1ThmJq7xwPqdQlgAbKX3fb0oZNbtRIyA5KQ==", "dev": true, "requires": { "@babel/helper-module-imports": "^7.12.13", @@ -149,8 +149,8 @@ "@babel/helper-split-export-declaration": "^7.12.13", "@babel/helper-validator-identifier": "^7.12.11", "@babel/template": "^7.12.13", - "@babel/traverse": "^7.12.13", - "@babel/types": "^7.12.13", + "@babel/traverse": "^7.12.17", + "@babel/types": "^7.12.17", "lodash": "^4.17.19" } }, @@ -200,14 +200,14 @@ "dev": true }, "@babel/helpers": { - "version": "7.12.13", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.12.13.tgz", - "integrity": "sha512-oohVzLRZ3GQEk4Cjhfs9YkJA4TdIDTObdBEZGrd6F/T0GPSnuV6l22eMcxlvcvzVIPH3VTtxbseudM1zIE+rPQ==", + "version": "7.12.17", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.12.17.tgz", + "integrity": "sha512-tEpjqSBGt/SFEsFikKds1sLNChKKGGR17flIgQKXH4fG6m9gTgl3gnOC1giHNyaBCSKuTfxaSzHi7UnvqiVKxg==", "dev": true, "requires": { "@babel/template": "^7.12.13", - "@babel/traverse": "^7.12.13", - "@babel/types": "^7.12.13" + "@babel/traverse": "^7.12.17", + "@babel/types": "^7.12.17" } }, "@babel/highlight": { @@ -261,25 +261,25 @@ } }, "@babel/parser": { - "version": "7.12.16", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.12.16.tgz", - "integrity": "sha512-c/+u9cqV6F0+4Hpq01jnJO+GLp2DdT63ppz9Xa+6cHaajM9VFzK/iDXiKK65YtpeVwu+ctfS6iqlMqRgQRzeCw==", + "version": "7.12.17", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.12.17.tgz", + "integrity": "sha512-r1yKkiUTYMQ8LiEI0UcQx5ETw5dpTLn9wijn9hk6KkTtOK95FndDN10M+8/s6k/Ymlbivw0Av9q4SlgF80PtHg==", "dev": true } } }, "@babel/traverse": { - "version": "7.12.13", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.12.13.tgz", - "integrity": "sha512-3Zb4w7eE/OslI0fTp8c7b286/cQps3+vdLW3UcwC8VSJC6GbKn55aeVVu2QJNuCDoeKyptLOFrPq8WqZZBodyA==", + "version": "7.12.17", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.12.17.tgz", + "integrity": "sha512-LGkTqDqdiwC6Q7fWSwQoas/oyiEYw6Hqjve5KOSykXkmFJFqzvGMb9niaUEag3Rlve492Mkye3gLw9FTv94fdQ==", "dev": true, "requires": { "@babel/code-frame": "^7.12.13", - "@babel/generator": "^7.12.13", + "@babel/generator": "^7.12.17", "@babel/helper-function-name": "^7.12.13", "@babel/helper-split-export-declaration": "^7.12.13", - "@babel/parser": "^7.12.13", - "@babel/types": "^7.12.13", + "@babel/parser": "^7.12.17", + "@babel/types": "^7.12.17", "debug": "^4.1.0", "globals": "^11.1.0", "lodash": "^4.17.19" @@ -295,9 +295,9 @@ } }, "@babel/parser": { - "version": "7.12.16", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.12.16.tgz", - "integrity": "sha512-c/+u9cqV6F0+4Hpq01jnJO+GLp2DdT63ppz9Xa+6cHaajM9VFzK/iDXiKK65YtpeVwu+ctfS6iqlMqRgQRzeCw==", + "version": "7.12.17", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.12.17.tgz", + "integrity": "sha512-r1yKkiUTYMQ8LiEI0UcQx5ETw5dpTLn9wijn9hk6KkTtOK95FndDN10M+8/s6k/Ymlbivw0Av9q4SlgF80PtHg==", "dev": true }, "globals": { @@ -309,9 +309,9 @@ } }, "@babel/types": { - "version": "7.12.13", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.12.13.tgz", - "integrity": "sha512-oKrdZTld2im1z8bDwTOQvUbxKwE+854zc16qWZQlcTqMN00pWxHQ4ZeOq0yDMnisOpRykH2/5Qqcrk/OlbAjiQ==", + "version": "7.12.17", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.12.17.tgz", + "integrity": "sha512-tNMDjcv/4DIcHxErTgwB9q2ZcYyN0sUfgGKUK/mm1FJK7Wz+KstoEekxrl/tBiNDgLK1HGi+sppj1An/1DR4fQ==", "dev": true, "requires": { "@babel/helper-validator-identifier": "^7.12.11", @@ -4392,9 +4392,9 @@ }, "dependencies": { "ajv": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-7.1.0.tgz", - "integrity": "sha512-svS9uILze/cXbH0z2myCK2Brqprx/+JJYK5pHicT/GQiBfzzhUVAIT6MwqJg8y4xV/zoGsUeuPuwtoiKSGE15g==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-7.1.1.tgz", + "integrity": "sha512-ga/aqDYnUy/o7vbsRTFhhTsNeXiYb5JWDIcRIeZfwRNCefwjNTVYCGdGSUrEmiu3yDK3vFvNbgJxvrQW4JXrYQ==", "dev": true, "requires": { "fast-deep-equal": "^3.1.1", diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 0a6530e3..03d954fe 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -41,11 +41,6 @@ export abstract class AbstractWorker< */ protected readonly interval?: NodeJS.Timeout - /** - * This value is immediately set to true when the kill from the main worker is received. - */ - private isKilled: boolean = false - /** * Constructs a new poolifier worker. * @@ -95,7 +90,6 @@ export abstract class AbstractWorker< this.mainWorker = value.parent } else if (value.kill) { // Here is time to kill this worker, just clearing the interval - this.isKilled = true if (this.interval) clearInterval(this.interval) this.emitDestroy() } @@ -134,7 +128,7 @@ export abstract class AbstractWorker< * Check to see if the worker should be terminated, because its living too long. */ protected checkAlive (): void { - if (Date.now() - this.lastTask > this.maxInactiveTime && !this.isKilled) { + if (Date.now() - this.lastTask > this.maxInactiveTime) { this.sendToMainWorker({ kill: this.killBehavior }) } } diff --git a/tests/pools/cluster/dynamic.test.js b/tests/pools/cluster/dynamic.test.js index fbeb77cf..2cff475f 100644 --- a/tests/pools/cluster/dynamic.test.js +++ b/tests/pools/cluster/dynamic.test.js @@ -62,8 +62,10 @@ describe('Dynamic cluster pool test suite ', () => { 1, './tests/worker-files/cluster/testWorker.js' ) - const res = await pool1.execute({ test: 'test' }) - expect(res).toBeFalsy() + const result = await pool1.execute({ test: 'test' }) + expect(result).toBeFalsy() + // We need to clean up the resources after our test + await pool1.destroy() }) it('Verify scale processes up and down is working when long running task is used:hard', async () => { @@ -80,6 +82,8 @@ describe('Dynamic cluster pool test suite ', () => { await TestUtils.waitExits(longRunningPool, max - min) // Here we expect the workers to be at the max size since that the task is still running expect(longRunningPool.workers.length).toBe(min) + // We need to clean up the resources after our test + await longRunningPool.destroy() }) it('Verify scale processes up and down is working when long running task is used:soft', async () => { @@ -96,5 +100,7 @@ describe('Dynamic cluster 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/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 08476e09..63399c6e 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -42,6 +42,15 @@ const asyncPool = new FixedClusterPool( ) describe('Fixed cluster 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 asyncErrorPool.destroy() + await emptyPool.destroy() + }) + it('Choose worker round robin test', async () => { const results = new Set() for (let i = 0; i < numberOfWorkers; i++) { @@ -129,5 +138,7 @@ describe('Fixed cluster 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() }) })