1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5const { fork, spawn } = require('child_process'); 6const net = require('net'); 7 8const tmpdir = require('../common/tmpdir'); 9 10// Run in a child process because the PIPE file descriptor stays open until 11// Node.js completes, blocking the tmpdir and preventing cleanup. 12 13if (process.argv[2] !== 'child') { 14 // Parent 15 tmpdir.refresh(); 16 17 // Run test 18 const child = fork(__filename, ['child'], { stdio: 'inherit' }); 19 child.on('exit', common.mustCall(function(code) { 20 assert.strictEqual(code, 0); 21 })); 22 23 return; 24} 25 26// Child 27const server = net.createServer((conn) => { 28 spawn(process.execPath, ['-v'], { 29 stdio: ['ignore', conn, 'ignore'] 30 }).on('close', common.mustCall(() => { 31 conn.end(); 32 })); 33}).listen(common.PIPE, () => { 34 const client = net.connect(common.PIPE, common.mustCall()); 35 client.once('data', () => { 36 client.end(() => { 37 server.close(); 38 }); 39 }); 40}); 41