Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
tests: fix process.kill pid test.
Browse files Browse the repository at this point in the history
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 <tjfontaine@gmail.com>
  • Loading branch information
Julien Gilli authored and tjfontaine committed Jul 29, 2014
1 parent e1fb1b5 commit ef3c4ed
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion test/simple/test-process-kill-pid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');

0 comments on commit ef3c4ed

Please sign in to comment.