test: improve test-process-kill-null for Windows

PR-URL: https://github.com/nodejs/node/pull/14099
Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
starkwang 2017-07-06 15:13:24 +08:00 committed by Refael Ackermann
parent b647f04df1
commit 44483b6898
No known key found for this signature in database
GPG Key ID: CD704BD80FDDDB64

View File

@ -20,29 +20,23 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE. // USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const spawn = require('child_process').spawn; const spawn = require('child_process').spawn;
const cat = spawn('cat'); const child = common.isWindows ? spawn('cmd.exe') : spawn('cat');
let called;
assert.ok(process.kill(cat.pid, 0)); assert.ok(process.kill(child.pid, 0));
cat.on('exit', function() { child.on('exit', common.mustCall(function() {
assert.throws(function() { assert.throws(function() {
process.kill(cat.pid, 0); process.kill(child.pid, 0);
}, Error); }, Error);
}); }));
cat.stdout.on('data', function() { child.stdout.on('data', common.mustCall(function() {
called = true; process.kill(child.pid, 'SIGKILL');
process.kill(cat.pid, 'SIGKILL'); }));
});
// EPIPE when null sig fails // EPIPE when null sig fails
cat.stdin.write('test'); child.stdin.write('test');
process.on('exit', function() {
assert.ok(called);
});