2018-09-17 09:16:44 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2019-07-30 08:50:21 +02:00
|
|
|
const assert = require('assert');
|
|
|
|
const { fork, spawn } = require('child_process');
|
2018-09-17 09:16:44 +02:00
|
|
|
const net = require('net');
|
|
|
|
|
2019-03-18 10:47:45 +01:00
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
|
2019-07-30 08:50:21 +02:00
|
|
|
// 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
|
2018-09-17 09:16:44 +02:00
|
|
|
const server = net.createServer((conn) => {
|
|
|
|
spawn(process.execPath, ['-v'], {
|
|
|
|
stdio: ['ignore', conn, 'ignore']
|
2019-04-23 21:08:14 +02:00
|
|
|
}).on('close', common.mustCall(() => {
|
|
|
|
conn.end();
|
|
|
|
}));
|
2018-09-17 09:16:44 +02:00
|
|
|
}).listen(common.PIPE, () => {
|
|
|
|
const client = net.connect(common.PIPE, common.mustCall());
|
2019-09-28 07:33:47 +02:00
|
|
|
client.once('data', () => {
|
2018-09-17 09:16:44 +02:00
|
|
|
client.end(() => {
|
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|