mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
75b30c606c
errorOrDestroy emits 'error' synchronously due to compat reasons. However, it should be possible to use correct async behaviour for new code. PR-URL: https://github.com/nodejs/node/pull/29744 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
41 lines
985 B
JavaScript
41 lines
985 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { fork, spawn } = require('child_process');
|
|
const net = require('net');
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
// Run in a child process because the PIPE file descriptor stays open until
|
|
// Node.js completes, blocking the tmpdir and preventing cleanup.
|
|
|
|
if (process.argv[2] !== 'child') {
|
|
// Parent
|
|
tmpdir.refresh();
|
|
|
|
// Run test
|
|
const child = fork(__filename, ['child'], { stdio: 'inherit' });
|
|
child.on('exit', common.mustCall(function(code) {
|
|
assert.strictEqual(code, 0);
|
|
}));
|
|
|
|
return;
|
|
}
|
|
|
|
// Child
|
|
const server = net.createServer((conn) => {
|
|
spawn(process.execPath, ['-v'], {
|
|
stdio: ['ignore', conn, 'ignore']
|
|
}).on('close', common.mustCall(() => {
|
|
conn.end();
|
|
}));
|
|
}).listen(common.PIPE, () => {
|
|
const client = net.connect(common.PIPE, common.mustCall());
|
|
client.once('data', () => {
|
|
client.end(() => {
|
|
server.close();
|
|
});
|
|
});
|
|
});
|