summaryrefslogtreecommitdiff
path: root/test/parallel/test-stdio-pipe-access.js
blob: ef84bb83803b2633e51922f5d7ffa05647e09cc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';
require('../common');

// Test if Node handles acessing process.stdin if it is a redirected
// pipe without deadlocking
const { spawn, spawnSync } = require('child_process');

const numTries = 5;
const who = process.argv.length <= 2 ? 'runner' : process.argv[2];

switch (who) {
  case 'runner':
    for (let num = 0; num < numTries; ++num) {
      spawnSync(process.argv0,
                [process.argv[1], 'parent'],
                { 'stdio': 'inherit' });
    }
    break;
  case 'parent':
    const middle = spawn(process.argv0,
                         [process.argv[1], 'middle'],
                         { 'stdio': 'pipe' });
    middle.stdout.on('data', () => {});
    break;
  case 'middle':
    spawn(process.argv0,
          [process.argv[1], 'bottom'],
          { 'stdio': [ process.stdin,
                       process.stdout,
                       process.stderr ] });
    break;
  case 'bottom':
    process.stdin;
    break;
}