From dc5617a30575201a0abc1416d4f92bb107628661 Mon Sep 17 00:00:00 2001 From: Carlos Espa Date: Thu, 12 Jan 2023 12:38:08 +0100 Subject: [PATCH 01/10] feat: message added on error due to forcefull termination --- README.md | 2 ++ bin.js | 1 + package.json | 1 + test/fail.js | 15 +++++++++++++++ test/fix-333.test.js | 17 +++++++++++++++++ 5 files changed, 36 insertions(+) create mode 100644 test/fail.js create mode 100644 test/fix-333.test.js diff --git a/README.md b/README.md index eedda55..59c0416 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ optimizations on background threads. With worker threads, the CPU will also utilize more than 100%. The visible percentage is always the combination of all these factors together. +__NOTE__: Exiting the process forcefully can result in wrong or no generation of log files. + ### Windows + PowerShell In order to diagnose your application with node clinic, you should execute your application after double hyphens(`--`), diff --git a/bin.js b/bin.js index 0f9973f..296dfbf 100755 --- a/bin.js +++ b/bin.js @@ -413,6 +413,7 @@ async function runTool (toolName, Tool, version, args, uiOptions) { if (err) return defer.reject(err) viz(toolName, filename, function (err) { + if (err?.code === 'ENOENT' && err?.message.includes('processstat')) return defer.reject(new Error('Process forcefully closed before processstat file generation')) if (err) return defer.reject(err) /* istanbul ignore if: isEnabled is always false when spawn process. See: https://github.com/sindresorhus/ora#isenabled */ if (spinner.isEnabled) { diff --git a/package.json b/package.json index aeddf1d..1ada5fc 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ }, "devDependencies": { "proxyquire": "^2.1.0", + "shelljs": "^0.8.5", "snazzy": "^9.0.0", "standard": "^17.0.0", "tap": "^16.0.0", diff --git a/test/fail.js b/test/fail.js new file mode 100644 index 0000000..626a52e --- /dev/null +++ b/test/fail.js @@ -0,0 +1,15 @@ +const async = require('async') +const shell = require('shelljs') + +module.exports = function (exit) { + async.waterfall([ + function (next) { + next() + }, + function (next) { + next() + } + ], exit) +} + +!module.parent && module.exports(shell.exit) diff --git a/test/fix-333.test.js b/test/fix-333.test.js new file mode 100644 index 0000000..b2b0187 --- /dev/null +++ b/test/fix-333.test.js @@ -0,0 +1,17 @@ +'use strict' + +const path = require('path') +const test = require('tap').test +const cli = require('./cli.js') + +test('clinic doctor throws error when process is forcefully closed before processstat', function (t) { + // collect data + cli({}, [ + 'clinic', 'doctor', '--no-open', + '--', 'node', path.join(__dirname, 'fail.js') + ], function (err, stdout, stderr) { + t.ok(err) + t.ok(stderr.includes('Process forcefully closed before processstat file generation')) + t.end() + }) +}) From ffde2378a3d76099db12893b05b7fab894900ed9 Mon Sep 17 00:00:00 2001 From: Carlos Espa Date: Thu, 12 Jan 2023 12:52:45 +0100 Subject: [PATCH 02/10] chore: renames --- ...fix-333.test.js => cli-doctor-forcefull-termination.test.js} | 2 +- test/{fail.js => forceful-termination.js} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename test/{fix-333.test.js => cli-doctor-forcefull-termination.test.js} (88%) rename test/{fail.js => forceful-termination.js} (100%) diff --git a/test/fix-333.test.js b/test/cli-doctor-forcefull-termination.test.js similarity index 88% rename from test/fix-333.test.js rename to test/cli-doctor-forcefull-termination.test.js index b2b0187..fc92f8c 100644 --- a/test/fix-333.test.js +++ b/test/cli-doctor-forcefull-termination.test.js @@ -4,7 +4,7 @@ const path = require('path') const test = require('tap').test const cli = require('./cli.js') -test('clinic doctor throws error when process is forcefully closed before processstat', function (t) { +test('clinic doctor throws error when process is forcefully closed before processstat file is generated', function (t) { // collect data cli({}, [ 'clinic', 'doctor', '--no-open', diff --git a/test/fail.js b/test/forceful-termination.js similarity index 100% rename from test/fail.js rename to test/forceful-termination.js From 8ef83a508c86a88b49adbfbec4a8ddf61f25fcfc Mon Sep 17 00:00:00 2001 From: Carlos Espa Date: Thu, 12 Jan 2023 12:53:55 +0100 Subject: [PATCH 03/10] chore: renames --- ...ermination.test.js => cli-doctor-forceful-termination.test.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{cli-doctor-forcefull-termination.test.js => cli-doctor-forceful-termination.test.js} (100%) diff --git a/test/cli-doctor-forcefull-termination.test.js b/test/cli-doctor-forceful-termination.test.js similarity index 100% rename from test/cli-doctor-forcefull-termination.test.js rename to test/cli-doctor-forceful-termination.test.js From 2d9a5d2ed1bb1c6161f7970e7cc56efa0ff38182 Mon Sep 17 00:00:00 2001 From: Carlos Espa Date: Thu, 12 Jan 2023 17:44:02 +0100 Subject: [PATCH 04/10] chore: shelljs removed --- package.json | 1 - test/forceful-termination.js | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/package.json b/package.json index 1ada5fc..aeddf1d 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ }, "devDependencies": { "proxyquire": "^2.1.0", - "shelljs": "^0.8.5", "snazzy": "^9.0.0", "standard": "^17.0.0", "tap": "^16.0.0", diff --git a/test/forceful-termination.js b/test/forceful-termination.js index 626a52e..880f5be 100644 --- a/test/forceful-termination.js +++ b/test/forceful-termination.js @@ -1,5 +1,4 @@ const async = require('async') -const shell = require('shelljs') module.exports = function (exit) { async.waterfall([ @@ -12,4 +11,4 @@ module.exports = function (exit) { ], exit) } -!module.parent && module.exports(shell.exit) +!module.parent && module.exports(process.exit) From 9f387351467b18ba78f50182bde90282913e26ce Mon Sep 17 00:00:00 2001 From: Carlos Espa Date: Thu, 12 Jan 2023 19:04:37 +0100 Subject: [PATCH 05/10] chore: fix mismatching file name --- test/cli-doctor-forceful-termination.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli-doctor-forceful-termination.test.js b/test/cli-doctor-forceful-termination.test.js index fc92f8c..538c3fc 100644 --- a/test/cli-doctor-forceful-termination.test.js +++ b/test/cli-doctor-forceful-termination.test.js @@ -8,7 +8,7 @@ test('clinic doctor throws error when process is forcefully closed before proces // collect data cli({}, [ 'clinic', 'doctor', '--no-open', - '--', 'node', path.join(__dirname, 'fail.js') + '--', 'node', path.join(__dirname, 'forceful-termination.js') ], function (err, stdout, stderr) { t.ok(err) t.ok(stderr.includes('Process forcefully closed before processstat file generation')) From bdeae34ca94f0bce8afd8fa2edd69efef9fc587f Mon Sep 17 00:00:00 2001 From: Carlos Espa Date: Wed, 18 Jan 2023 11:21:44 +0100 Subject: [PATCH 06/10] chore: forcefull termination test skipped on node v14 --- bin.js | 1 + package.json | 2 +- test/cli-doctor-forceful-termination.test.js | 9 +++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bin.js b/bin.js index 296dfbf..24df52d 100755 --- a/bin.js +++ b/bin.js @@ -413,6 +413,7 @@ async function runTool (toolName, Tool, version, args, uiOptions) { if (err) return defer.reject(err) viz(toolName, filename, function (err) { + console.log(err) if (err?.code === 'ENOENT' && err?.message.includes('processstat')) return defer.reject(new Error('Process forcefully closed before processstat file generation')) if (err) return defer.reject(err) /* istanbul ignore if: isEnabled is always false when spawn process. See: https://github.com/sindresorhus/ora#isenabled */ diff --git a/package.json b/package.json index aeddf1d..875e233 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "test-local": "standard | snazzy && tap --no-cov test/*.test.js test-local/*.test.js", "ci-lint": "standard | snazzy", "ci-test-no-cov": "tap --no-cov test/*.test.js", - "ci-test-cov": "tap test/*.test.js", + "ci-test-cov": "tap --grep=/^test\/(?!.*cli-doctor-forceful-termination\\.test\\.js$).*\\.test\\.js$/", "lint": "standard --fix | snazzy" }, "dependencies": { diff --git a/test/cli-doctor-forceful-termination.test.js b/test/cli-doctor-forceful-termination.test.js index 538c3fc..c42c627 100644 --- a/test/cli-doctor-forceful-termination.test.js +++ b/test/cli-doctor-forceful-termination.test.js @@ -3,15 +3,20 @@ const path = require('path') const test = require('tap').test const cli = require('./cli.js') +const fs = require('fs') -test('clinic doctor throws error when process is forcefully closed before processstat file is generated', function (t) { +test('clinic doctor throws error when process is forcefully closed before processstat file is generated', { skip: process.version.startsWith('v14')}, function (t) { // collect data cli({}, [ 'clinic', 'doctor', '--no-open', '--', 'node', path.join(__dirname, 'forceful-termination.js') - ], function (err, stdout, stderr) { + ], function (err, stdout, stderr, tempdir) { + console.log(stdout) + console.log(stderr) + const dirname = stdout.match(/(\.clinic[/\\]\d+.clinic-doctor)/)[1] t.ok(err) t.ok(stderr.includes('Process forcefully closed before processstat file generation')) + t.ok(fs.existsSync(path.resolve(tempdir, dirname + '-processstat'))) t.end() }) }) From eac47f43daec5a7262a63a039093eb0a59e41c45 Mon Sep 17 00:00:00 2001 From: Carlos Espa <43477095+Ceres6@users.noreply.github.com> Date: Thu, 19 Jan 2023 12:42:23 +0100 Subject: [PATCH 07/10] Update bin.js Co-authored-by: Rafael Gonzaga --- bin.js | 1 - 1 file changed, 1 deletion(-) diff --git a/bin.js b/bin.js index 24df52d..296dfbf 100755 --- a/bin.js +++ b/bin.js @@ -413,7 +413,6 @@ async function runTool (toolName, Tool, version, args, uiOptions) { if (err) return defer.reject(err) viz(toolName, filename, function (err) { - console.log(err) if (err?.code === 'ENOENT' && err?.message.includes('processstat')) return defer.reject(new Error('Process forcefully closed before processstat file generation')) if (err) return defer.reject(err) /* istanbul ignore if: isEnabled is always false when spawn process. See: https://github.com/sindresorhus/ora#isenabled */ From 3c92505ace5ffb37c8b109a5c274370f87454432 Mon Sep 17 00:00:00 2001 From: Carlos Espa Date: Thu, 19 Jan 2023 12:55:05 +0100 Subject: [PATCH 08/10] chore: pr comments addressed --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 875e233..aeddf1d 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "test-local": "standard | snazzy && tap --no-cov test/*.test.js test-local/*.test.js", "ci-lint": "standard | snazzy", "ci-test-no-cov": "tap --no-cov test/*.test.js", - "ci-test-cov": "tap --grep=/^test\/(?!.*cli-doctor-forceful-termination\\.test\\.js$).*\\.test\\.js$/", + "ci-test-cov": "tap test/*.test.js", "lint": "standard --fix | snazzy" }, "dependencies": { From a977424948b6d698ba3d0e7f56f15e14eb984836 Mon Sep 17 00:00:00 2001 From: Carlos Espa Date: Wed, 22 Feb 2023 20:34:39 +0100 Subject: [PATCH 09/10] chore: lint fixed --- test/cli-doctor-forceful-termination.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli-doctor-forceful-termination.test.js b/test/cli-doctor-forceful-termination.test.js index c42c627..9ff4480 100644 --- a/test/cli-doctor-forceful-termination.test.js +++ b/test/cli-doctor-forceful-termination.test.js @@ -5,7 +5,7 @@ const test = require('tap').test const cli = require('./cli.js') const fs = require('fs') -test('clinic doctor throws error when process is forcefully closed before processstat file is generated', { skip: process.version.startsWith('v14')}, function (t) { +test('clinic doctor throws error when process is forcefully closed before processstat file is generated', { skip: process.version.startsWith('v14') }, function (t) { // collect data cli({}, [ 'clinic', 'doctor', '--no-open', From abdb53b325900ab9b85f16d29e8c072c83701d32 Mon Sep 17 00:00:00 2001 From: Carlos Espa Date: Wed, 22 Feb 2023 20:44:14 +0100 Subject: [PATCH 10/10] test: test fixed --- test/cli-doctor-forceful-termination.test.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/cli-doctor-forceful-termination.test.js b/test/cli-doctor-forceful-termination.test.js index 9ff4480..4dcd66b 100644 --- a/test/cli-doctor-forceful-termination.test.js +++ b/test/cli-doctor-forceful-termination.test.js @@ -3,20 +3,15 @@ const path = require('path') const test = require('tap').test const cli = require('./cli.js') -const fs = require('fs') test('clinic doctor throws error when process is forcefully closed before processstat file is generated', { skip: process.version.startsWith('v14') }, function (t) { // collect data cli({}, [ 'clinic', 'doctor', '--no-open', '--', 'node', path.join(__dirname, 'forceful-termination.js') - ], function (err, stdout, stderr, tempdir) { - console.log(stdout) - console.log(stderr) - const dirname = stdout.match(/(\.clinic[/\\]\d+.clinic-doctor)/)[1] + ], function (err, stdout, stderr) { t.ok(err) t.ok(stderr.includes('Process forcefully closed before processstat file generation')) - t.ok(fs.existsSync(path.resolve(tempdir, dirname + '-processstat'))) t.end() }) })