From ef3c4ed3dd23522d871e5951766441a7a0512f47 Mon Sep 17 00:00:00 2001 From: Julien Gilli Date: Mon, 28 Jul 2014 17:19:03 -0700 Subject: [PATCH] tests: fix process.kill pid test. Prevent test-process-kill-pid.js tests suite from sending SIGHUP to its process group, which was causing the test runner to terminate. Fix jenkins' jobs for nodejs-master. Signed-off-by: Timothy J Fontaine --- test/simple/test-process-kill-pid.js | 31 +++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/test/simple/test-process-kill-pid.js b/test/simple/test-process-kill-pid.js index af65b64718b..e56295672f4 100644 --- a/test/simple/test-process-kill-pid.js +++ b/test/simple/test-process-kill-pid.js @@ -43,7 +43,9 @@ process.on('exit', function(code) { // // Nan, Infinity, -Infinity: TypeError // -// 0, process.pid: ourself +// 0: our group process +// +// process.pid: ourself assert.throws(function() { process.kill('SIGTERM'); }, TypeError); assert.throws(function() { process.kill(String(process.pid)); }, TypeError); @@ -61,4 +63,31 @@ process.once('SIGHUP', function() { process.kill(process.pid, 'SIGHUP'); }); + +/* + * Monkey patch _kill so that, in the specific case + * when we want to test sending a signal to pid 0, + * we don't actually send the signal to the process group. + * Otherwise, it could cause a lot of trouble, like terminating + * the test runner, or any other process that belongs to the + * same process group as this test. + */ +var origKill = process._kill; +process._kill = function(pid, sig) { + /* + * make sure we patch _kill only when + * we want to test sending a signal + * to the process group. + */ + assert.strictEqual(pid, 0); + + // make sure that _kill is passed the correct args types + assert(typeof pid === 'number'); + assert(typeof sig === 'number'); + + // un-monkey patch process._kill + process._kill = origKill; + process._kill(process.pid, sig); +} + process.kill(0, 'SIGHUP');