11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst { fork, spawn } = require('child_process'); 61cb0ef41Sopenharmony_ciconst net = require('net'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci// Run in a child process because the PIPE file descriptor stays open until 111cb0ef41Sopenharmony_ci// Node.js completes, blocking the tmpdir and preventing cleanup. 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciif (process.argv[2] !== 'child') { 141cb0ef41Sopenharmony_ci // Parent 151cb0ef41Sopenharmony_ci tmpdir.refresh(); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci // Run test 181cb0ef41Sopenharmony_ci const child = fork(__filename, ['child'], { stdio: 'inherit' }); 191cb0ef41Sopenharmony_ci child.on('exit', common.mustCall(function(code) { 201cb0ef41Sopenharmony_ci assert.strictEqual(code, 0); 211cb0ef41Sopenharmony_ci })); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci return; 241cb0ef41Sopenharmony_ci} 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci// Child 271cb0ef41Sopenharmony_ciconst server = net.createServer((conn) => { 281cb0ef41Sopenharmony_ci spawn(process.execPath, ['-v'], { 291cb0ef41Sopenharmony_ci stdio: ['ignore', conn, 'ignore'] 301cb0ef41Sopenharmony_ci }).on('close', common.mustCall(() => { 311cb0ef41Sopenharmony_ci conn.end(); 321cb0ef41Sopenharmony_ci })); 331cb0ef41Sopenharmony_ci}).listen(common.PIPE, () => { 341cb0ef41Sopenharmony_ci const client = net.connect(common.PIPE, common.mustCall()); 351cb0ef41Sopenharmony_ci client.once('data', () => { 361cb0ef41Sopenharmony_ci client.end(() => { 371cb0ef41Sopenharmony_ci server.close(); 381cb0ef41Sopenharmony_ci }); 391cb0ef41Sopenharmony_ci }); 401cb0ef41Sopenharmony_ci}); 41