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 <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 488e1bb commit 83e704d

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
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+
constnumTries=5;
9+
constwho=process.argv.length<=2 ? 'runner' : process.argv[2];
10+
11+
switch(who){
12+
case'runner':
13+
for(letnum=0;num<numTries;++num){
14+
spawnSync(process.argv0,
15+
[process.argv[1],'parent'],
16+
{'stdio': 'inherit'});
17+
}
18+
break;
19+
case'parent':
20+
constmiddle=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+
}
Lines changed: 38 additions & 0 deletions
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+
constspawn=require('child_process').spawn;
7+
8+
constwriteSize=100;
9+
consttotalDots=10000;
10+
11+
constwho=process.argv.length<=2 ? 'parent' : process.argv[2];
12+
13+
switch(who){
14+
case'parent':
15+
constconsumer=spawn(process.argv0,[process.argv[1],'consumer'],{
16+
stdio: ['pipe','ignore','inherit'],
17+
});
18+
constproducer=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+
constbuffer=Buffer.alloc(writeSize,'.');
26+
letwritten=0;
27+
constwrite=()=>{
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)