From b0d675df28efda2898c6621851904c0565988363 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Sun, 12 Nov 2017 09:47:14 +0000 Subject: [PATCH 1/3] test: pass test function to expectsError PR-URL: https://github.com/nodejs/node/pull/16944 Reviewed-By: Colin Ihrig Reviewed-By: Anna Henningsen --- test/parallel/test-process-kill-pid.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-process-kill-pid.js b/test/parallel/test-process-kill-pid.js index b020f6bc615b3c..8171b644577e65 100644 --- a/test/parallel/test-process-kill-pid.js +++ b/test/parallel/test-process-kill-pid.js @@ -57,17 +57,13 @@ assert.throws(function() { process.kill(1 / 0); }, assert.throws(function() { process.kill(-1 / 0); }, invalidPidArgument); -// Test that kill throws an error for invalid signal -const unknownSignal = common.expectsError({ +// Test that kill throws an error for unknown signal names +common.expectsError(() => process.kill(1, 'test'), { code: 'ERR_UNKNOWN_SIGNAL', type: TypeError, message: 'Unknown signal: test' }); - -assert.throws(function() { process.kill(1, 'test'); }, - unknownSignal); - // Test kill argument processing in valid cases. // // Monkey patch _kill so that we don't actually send any signals, particularly From 515f415258ee2e62128cc5df760d9c3462729a4a Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Fri, 10 Nov 2017 13:17:25 +0000 Subject: [PATCH 2/3] lib: allow process kill by signal number This brings the behaviour in line with the documentation. PR-URL: https://github.com/nodejs/node/pull/16944 Reviewed-By: Colin Ihrig Reviewed-By: Anna Henningsen --- lib/internal/process.js | 4 ++-- test/parallel/test-process-kill-pid.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/internal/process.js b/lib/internal/process.js index ff5ea58dda5f6c..181fffef9f587b 100644 --- a/lib/internal/process.js +++ b/lib/internal/process.js @@ -158,8 +158,8 @@ function setupKillAndExit() { } // preserve null signal - if (0 === sig) { - err = process._kill(pid, 0); + if (sig === (sig | 0)) { + err = process._kill(pid, sig); } else { sig = sig || 'SIGTERM'; if (constants[sig]) { diff --git a/test/parallel/test-process-kill-pid.js b/test/parallel/test-process-kill-pid.js index 8171b644577e65..689d774c6337b1 100644 --- a/test/parallel/test-process-kill-pid.js +++ b/test/parallel/test-process-kill-pid.js @@ -64,6 +64,13 @@ common.expectsError(() => process.kill(1, 'test'), { message: 'Unknown signal: test' }); +// Test that kill throws an error for invalid signal numbers +common.expectsError(() => process.kill(1, 987), { + code: 'EINVAL', + type: Error, + message: 'kill EINVAL' +}); + // Test kill argument processing in valid cases. // // Monkey patch _kill so that we don't actually send any signals, particularly @@ -95,6 +102,11 @@ kill(0, undefined, 0, 15); kill('0', 'SIGHUP', 0, 1); kill('0', undefined, 0, 15); +// Confirm that numeric signal arguments are supported + +kill(0, 1, 0, 1); +kill(0, 15, 0, 15); + // negative numbers are meaningful on unix kill(-1, 'SIGHUP', -1, 1); kill(-1, undefined, -1, 15); From f1a582ab9fdc8c477f3bca748f9c69244dd276bf Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 17 Feb 2018 01:08:16 +0100 Subject: [PATCH 3/3] fixup test --- test/parallel/test-process-kill-pid.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-process-kill-pid.js b/test/parallel/test-process-kill-pid.js index 689d774c6337b1..9b11bf94a9f450 100644 --- a/test/parallel/test-process-kill-pid.js +++ b/test/parallel/test-process-kill-pid.js @@ -58,14 +58,14 @@ assert.throws(function() { process.kill(-1 / 0); }, invalidPidArgument); // Test that kill throws an error for unknown signal names -common.expectsError(() => process.kill(1, 'test'), { +common.expectsError(() => process.kill(0, 'test'), { code: 'ERR_UNKNOWN_SIGNAL', type: TypeError, message: 'Unknown signal: test' }); // Test that kill throws an error for invalid signal numbers -common.expectsError(() => process.kill(1, 987), { +common.expectsError(() => process.kill(0, 987), { code: 'EINVAL', type: Error, message: 'kill EINVAL'