node/test/simple/test-child-process-kill.js

43 lines
803 B
JavaScript
Raw Normal View History

2010-12-05 07:20:34 +08:00
var common = require('../common');
var assert = require('assert');
2010-03-18 05:00:17 +08:00
var spawn = require('child_process').spawn;
var exitCode;
var termSignal;
2010-03-18 05:00:17 +08:00
var gotStdoutEOF = false;
var gotStderrEOF = false;
var cat = spawn('cat');
2010-03-18 05:00:17 +08:00
cat.stdout.addListener('data', function(chunk) {
2010-03-18 05:00:17 +08:00
assert.ok(false);
});
cat.stdout.addListener('end', function() {
2010-03-18 05:00:17 +08:00
gotStdoutEOF = true;
});
cat.stderr.addListener('data', function(chunk) {
2010-03-18 05:00:17 +08:00
assert.ok(false);
});
cat.stderr.addListener('end', function() {
2010-03-18 05:00:17 +08:00
gotStderrEOF = true;
});
cat.addListener('exit', function(code, signal) {
exitCode = code;
termSignal = signal;
2010-03-18 05:00:17 +08:00
});
cat.kill();
process.addListener('exit', function() {
assert.strictEqual(exitCode, null);
assert.strictEqual(termSignal, 'SIGTERM');
2010-03-18 05:00:17 +08:00
assert.ok(gotStdoutEOF);
assert.ok(gotStderrEOF);
});