mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
bb29405904
PR-URL: https://github.com/nodejs/node/pull/14162 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const cp = require('child_process');
|
|
const net = require('net');
|
|
|
|
if (process.argv[2] === 'child') {
|
|
process.stdout.write('this should be ignored');
|
|
process.stderr.write('this should not be ignored');
|
|
|
|
const pipe = new net.Socket({ fd: 4 });
|
|
|
|
process.on('disconnect', () => {
|
|
pipe.unref();
|
|
});
|
|
|
|
pipe.setEncoding('utf8');
|
|
pipe.on('data', (data) => {
|
|
process.send(data);
|
|
});
|
|
} else {
|
|
assert.throws(() => {
|
|
cp.fork(__filename, { stdio: ['pipe', 'pipe', 'pipe', 'pipe'] });
|
|
}, /Forked processes must have an IPC channel/);
|
|
|
|
let ipc = '';
|
|
let stderr = '';
|
|
const buf = Buffer.from('data to send via pipe');
|
|
const child = cp.fork(__filename, ['child'], {
|
|
stdio: [0, 'ignore', 'pipe', 'ipc', 'pipe']
|
|
});
|
|
|
|
assert.strictEqual(child.stdout, null);
|
|
|
|
child.on('message', (msg) => {
|
|
ipc += msg;
|
|
|
|
if (ipc === buf.toString()) {
|
|
child.disconnect();
|
|
}
|
|
});
|
|
|
|
child.stderr.on('data', (chunk) => {
|
|
stderr += chunk;
|
|
});
|
|
|
|
child.on('exit', common.mustCall((code, signal) => {
|
|
assert.strictEqual(code, 0);
|
|
assert.strictEqual(signal, null);
|
|
assert.strictEqual(stderr, 'this should not be ignored');
|
|
}));
|
|
|
|
child.stdio[4].write(buf);
|
|
}
|