1'use strict'; 2const common = require('../common'); 3if (!common.isMainThread) 4 common.skip("Workers don't have process-like stdio"); 5 6// Test if Node handles accessing process.stdin if it is a redirected 7// pipe without deadlocking 8const { spawn, spawnSync } = require('child_process'); 9 10const numTries = 5; 11const who = process.argv.length <= 2 ? 'runner' : process.argv[2]; 12 13switch (who) { 14 case 'runner': 15 for (let num = 0; num < numTries; ++num) { 16 spawnSync(process.argv0, 17 [process.argv[1], 'parent'], 18 { 'stdio': 'inherit' }); 19 } 20 break; 21 case 'parent': { 22 const middle = spawn(process.argv0, 23 [process.argv[1], 'middle'], 24 { 'stdio': 'pipe' }); 25 middle.stdout.on('data', () => {}); 26 break; 27 } 28 case 'middle': 29 spawn(process.argv0, 30 [process.argv[1], 'bottom'], 31 { 'stdio': [ process.stdin, 32 process.stdout, 33 process.stderr ] }); 34 break; 35 case 'bottom': 36 process.stdin; // eslint-disable-line no-unused-expressions 37 break; 38} 39