-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
test: add tests for end event of stream.Duplex #21325
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Added tests to check the stream will automatically end the writable side when readable side ends when allowHalfOpen option is false.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const Duplex = require('stream').Duplex; | ||
| { | ||
| const stream = new Duplex(); | ||
| assert(stream.allowHalfOpen); | ||
|
Contributor
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. Can you use
Contributor
Author
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. @cjihrig Fixed it. Thank you for your comment. |
||
| stream.on('finish', common.mustNotCall()); | ||
| assert.strictEqual(stream.emit('end'), false); | ||
|
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. I wonder if it's better to use
Contributor
Author
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. @lpinca Thanks for your review. Would you please tell me why it is better to use
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. That's how the If you switch the stream in flowing mode with const stream = new Duplex({ read() {} });
stream.resume();
stream.push(null);
Contributor
Author
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. I fixed it and the codes you indicated emit |
||
| } | ||
|
|
||
| { | ||
| const stream = new Duplex({ | ||
| allowHalfOpen: false | ||
| }); | ||
| assert.strictEqual(stream.allowHalfOpen, false); | ||
| stream.on('finish', common.mustCall()); | ||
| assert(stream.emit('end')); | ||
| } | ||
|
|
||
| { | ||
| const stream = new Duplex({ | ||
| allowHalfOpen: false | ||
| }); | ||
| assert.strictEqual(stream.allowHalfOpen, false); | ||
| stream._writableState.ended = true; | ||
| stream.on('finish', common.mustNotCall()); | ||
| assert(stream.emit('end')); | ||
| } | ||
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: can please add a new line before this?