Skip to content

Commit 83e704d

Browse files
bzozMylesBorins
authored andcommitted
test: stdio pipe behavior tests
Add two regression tests for stdio over pipes. test-stdio-pipe-access tests if accessing stdio pipe that is being read by another process does not deadlocks Node.js. This was reported in #10836 and was fixed in v8.3.0. The deadlock would happen intermittently, so we run the test 5 times. test-stdio-pipe-redirect tests if redirecting one child process stdin to another process stdout does not crash Node as reported in #17493. It was fixed in #18019. PR-URL: #18614 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 488e1bb commit 83e704d

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
require('../common');
3+
4+
// Test if Node handles acessing process.stdin if it is a redirected
5+
// pipe without deadlocking
6+
const { spawn, spawnSync } = require('child_process');
7+
8+
const numTries = 5;
9+
const who = process.argv.length <= 2 ? 'runner' : process.argv[2];
10+
11+
switch (who) {
12+
case 'runner':
13+
for (let num = 0; num < numTries; ++num) {
14+
spawnSync(process.argv0,
15+
[process.argv[1], 'parent'],
16+
{ 'stdio': 'inherit' });
17+
}
18+
break;
19+
case 'parent':
20+
const middle = spawn(process.argv0,
21+
[process.argv[1], 'middle'],
22+
{ 'stdio': 'pipe' });
23+
middle.stdout.on('data', () => {});
24+
break;
25+
case 'middle':
26+
spawn(process.argv0,
27+
[process.argv[1], 'bottom'],
28+
{ 'stdio': [ process.stdin,
29+
process.stdout,
30+
process.stderr ] });
31+
break;
32+
case 'bottom':
33+
process.stdin;
34+
break;
35+
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
require('../common');
3+
4+
// Test if Node handles redirecting one child process stdout to another
5+
// process stdin without crashing.
6+
const spawn = require('child_process').spawn;
7+
8+
const writeSize = 100;
9+
const totalDots = 10000;
10+
11+
const who = process.argv.length <= 2 ? 'parent' : process.argv[2];
12+
13+
switch (who) {
14+
case 'parent':
15+
const consumer = spawn(process.argv0, [process.argv[1], 'consumer'], {
16+
stdio: ['pipe', 'ignore', 'inherit'],
17+
});
18+
const producer = spawn(process.argv0, [process.argv[1], 'producer'], {
19+
stdio: ['pipe', consumer.stdin, 'inherit'],
20+
});
21+
process.stdin.on('data', () => {});
22+
producer.on('exit', process.exit);
23+
break;
24+
case 'producer':
25+
const buffer = Buffer.alloc(writeSize, '.');
26+
let written = 0;
27+
const write = () => {
28+
if (written < totalDots) {
29+
written += writeSize;
30+
process.stdout.write(buffer, write);
31+
}
32+
};
33+
write();
34+
break;
35+
case 'consumer':
36+
process.stdin.on('data', () => {});
37+
break;
38+
}

0 commit comments

Comments
 (0)