GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: stdio pipe behavior tests · nodejs/node@df0d78a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-stdio-pipe-access.js
    • test-stdio-pipe-redirect.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/parallel/test-stdio-pipe-access.js‎

Copy file name to clipboard
+35Lines 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+
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+
}
Collapse file

‎test/parallel/test-stdio-pipe-redirect.js‎

Copy file name to clipboard
+38Lines 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+
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 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.