-
-
Notifications
You must be signed in to change notification settings - Fork 36.6k
test: test for issue #5574 #5841
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
5 commits
Select commit
Hold shift + click to select a range
1d68574
Test for #5574
piranna 02ea325
Move test to know_issues
piranna 14b1144
Follow conventions and recommendations of @cjihrig
piranna 050e2bb
Moved test back to test/parallel folder
piranna 83c97f8
Swapped order of asserts to be ablet to know what signal finished the…
piranna 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 for #5574
Test that characters from stdin are not randomly lost when using a `readline.Interface` and a `tty.ReadStream` on `process.stdin`
- Loading branch information
commit 1d68574d50cc0761827b3285d9ba767baa55fd11
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,73 @@ | ||
| /** | ||
| * https://github.com/nodejs/node/issues/5574 | ||
| * | ||
| * Test that characters from stdin are not randomly lost when using a | ||
| * `readline.Interface` and a `tty.ReadStream` on `process.stdin` | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| var assert = require('assert'); | ||
| var Interface = require('readline').Interface; | ||
| var Readable = require('stream').Readable; | ||
| var ReadStream = require('tty').ReadStream; | ||
| var spawn = require('child_process').spawn; | ||
|
|
||
| var spawnCat = require('../common').spawnCat; | ||
|
|
||
|
|
||
| const kpm = 60; | ||
| const input = `1234567890 | ||
| qwertyuiop | ||
| asdfghjklñ | ||
| zxcvbnm`; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would prefer not using a multiline template literal. |
||
|
|
||
|
|
||
| if (process.argv[2] === 'parent') | ||
| parent(); | ||
| else | ||
| grandparent(); | ||
|
|
||
| function grandparent() { | ||
| var child = spawn(process.execPath, [__filename, 'parent']); | ||
| child.stderr.pipe(process.stderr); | ||
|
|
||
| var stdin = Readable({read: function() {}}); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| stdin.pipe(child.stdin); | ||
|
|
||
| var output = ''; | ||
| child.stdout.on('data', function(chunk) { | ||
| output += chunk; | ||
| }); | ||
| child.stdout.setEncoding('utf8'); | ||
|
|
||
| var index = 0; | ||
| function type() { | ||
| var data = input[index] || null; | ||
|
|
||
| stdin.push(data); | ||
| index++; | ||
|
|
||
| if (data !== null) return setTimeout(type, 60 * 1000 / kpm); | ||
| } | ||
|
|
||
| type(); | ||
|
|
||
| child.on('close', function(code, signal) { | ||
| assert.equal(code, 0); | ||
| assert.equal(signal, null); | ||
| // cat on windows adds a \r\n at the end. | ||
| assert.equal(output.trim(), input.trim()); | ||
| }); | ||
| } | ||
|
|
||
| function parent() { | ||
| Interface(process.stdin, process.stdout); | ||
|
|
||
| var stdin = ReadStream(process.stdin.fd); | ||
| process.stdin.pause(); | ||
|
|
||
| var stdio = [stdin, process.stdout]; | ||
|
|
||
| spawnCat({ stdio: stdio }); | ||
| } | ||
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.
Nit: Please use the
//style for these kinds of comments, just for consistency