-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
test: stdio pipe behavior tests #18614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
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.
- Loading branch information
commit 8aeee9c1d14aabac8a1ca65b5ee0ff7e2945ee56
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| '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) { | ||
| console.log('Try: ' + 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; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| 'use strict'; | ||
| require('../common'); | ||
|
|
||
| // Test if Node handles redirecting one child process stdout to another | ||
| // process stdin without crashing. | ||
| const spawn = require('child_process').spawn; | ||
|
|
||
| const writeSize = 100; | ||
| const totalDots = 10000; | ||
|
|
||
| const who = process.argv.length <= 2 ? 'parent' : process.argv[2]; | ||
|
|
||
| switch (who) { | ||
| case 'parent': | ||
| const consumer = spawn(process.argv0, [process.argv[1], 'consumer'], { | ||
| stdio: ['pipe', 'ignore', 'inherit'], | ||
| }); | ||
| const producer = spawn(process.argv0, [process.argv[1], 'producer'], { | ||
| stdio: ['pipe', consumer.stdin, 'inherit'], | ||
| }); | ||
| process.stdin.on('data', () => {}); | ||
| producer.on('exit', process.exit); | ||
| break; | ||
| case 'producer': | ||
| const buffer = Buffer.alloc(writeSize, '.'); | ||
| let written = 0; | ||
| const write = () => { | ||
| if (written < totalDots) { | ||
| written += writeSize; | ||
| process.stdout.write(buffer, write); | ||
| } | ||
| }; | ||
| write(); | ||
| break; | ||
| case 'consumer': | ||
| process.stdin.on('data', () => {}); | ||
| break; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the console.log output is a part of the test, can you add a comment indicating so. If it is not, I'd prefer it to be removed.