|
|
@ -35,22 +35,48 @@ exec("ls /DOES_NOT_EXIST", function (err, stdout, stderr) { |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sleeperStart = new Date(); |
|
|
|
exec("sleep 3", { timeout: 50 }, function (err, stdout, stderr) { |
|
|
|
var diff = (new Date()) - sleeperStart; |
|
|
|
console.log("sleep 3 with timeout 50 took %d ms", diff); |
|
|
|
assert.ok(diff < 500); |
|
|
|
assert.ok(err); |
|
|
|
assert.ok(err.killed); |
|
|
|
assert.equal(err.signal, 'SIGKILL'); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var killMeTwice = exec("sleep 3", { timeout: 1000 }, function killMeTwiceCallback(err, stdout, stderr) { |
|
|
|
assert.ok(err); |
|
|
|
assert.ok(err.killed); |
|
|
|
assert.equal(err.signal, 'SIGTERM'); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var startSleep3 = new Date(); |
|
|
|
var killMeTwice = exec("sleep 3", { timeout: 1000 }, killMeTwiceCallback); |
|
|
|
|
|
|
|
process.nextTick(function(){ |
|
|
|
console.log("kill pid %d", killMeTwice.pid); |
|
|
|
// make sure there is no race condition in starting the process
|
|
|
|
// the PID SHOULD exist directly following the exec() call.
|
|
|
|
assert.equal('number', typeof killMeTwice._internal.pid); |
|
|
|
// Kill the process
|
|
|
|
killMeTwice.kill(); |
|
|
|
}); |
|
|
|
|
|
|
|
function killMeTwiceCallback(err, stdout, stderr) { |
|
|
|
var diff = (new Date()) - startSleep3; |
|
|
|
// We should have already killed this process. Assert that
|
|
|
|
// the timeout still works and that we are getting the proper callback
|
|
|
|
// parameters.
|
|
|
|
assert.ok(err); |
|
|
|
assert.ok(err.killed); |
|
|
|
assert.equal(err.signal, 'SIGKILL'); |
|
|
|
|
|
|
|
// the timeout should still be in effect
|
|
|
|
console.log("'sleep 3' was already killed. Took %d ms", diff); |
|
|
|
assert.ok(diff < 1500); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exec('python -c "print 200000*\'C\'"', { maxBuffer: 1000 }, function (err, stdout, stderr) { |
|
|
|
assert.ok(err); |
|
|
|