-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
test: http2 client settings errors #16096
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 all commits
Commits
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
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,84 @@ | ||
| 'use strict'; | ||
|
|
||
| const { | ||
| constants, | ||
| Http2Session, | ||
| nghttp2ErrorString | ||
| } = process.binding('http2'); | ||
| const common = require('../common'); | ||
| if (!common.hasCrypto) | ||
| common.skip('missing crypto'); | ||
| const http2 = require('http2'); | ||
|
|
||
| // tests error handling within requestOnConnect | ||
| // - NGHTTP2_ERR_NOMEM (should emit session error) | ||
| // - every other NGHTTP2 error from binding (should emit session error) | ||
|
|
||
| const specificTestKeys = [ | ||
| 'NGHTTP2_ERR_NOMEM' | ||
| ]; | ||
|
|
||
| const specificTests = [ | ||
| { | ||
| ngError: constants.NGHTTP2_ERR_NOMEM, | ||
| error: { | ||
| code: 'ERR_OUTOFMEMORY', | ||
| type: Error, | ||
| message: 'Out of memory' | ||
| } | ||
| } | ||
| ]; | ||
|
|
||
| const genericTests = Object.getOwnPropertyNames(constants) | ||
| .filter((key) => ( | ||
| key.indexOf('NGHTTP2_ERR') === 0 && specificTestKeys.indexOf(key) < 0 | ||
| )) | ||
| .map((key) => ({ | ||
| ngError: constants[key], | ||
| error: { | ||
| code: 'ERR_HTTP2_ERROR', | ||
| type: Error, | ||
| message: nghttp2ErrorString(constants[key]) | ||
| } | ||
| })); | ||
|
|
||
| const tests = specificTests.concat(genericTests); | ||
|
|
||
| const server = http2.createServer(common.mustNotCall()); | ||
| server.on('sessionError', () => {}); // not being tested | ||
|
|
||
| server.listen(0, common.mustCall(() => runTest(tests.shift()))); | ||
|
|
||
| function runTest(test) { | ||
| // mock submitSettings because we only care about testing error handling | ||
| Http2Session.prototype.submitSettings = () => test.ngError; | ||
|
|
||
| const errorMustCall = common.expectsError(test.error); | ||
| const errorMustNotCall = common.mustNotCall( | ||
| `${test.error.code} should emit on session` | ||
| ); | ||
|
|
||
| const url = `http://localhost:${server.address().port}`; | ||
|
|
||
| const client = http2.connect(url, { | ||
| settings: { | ||
| maxHeaderListSize: 1 | ||
| } | ||
| }); | ||
|
|
||
| const req = client.request(); | ||
| req.resume(); | ||
| req.end(); | ||
|
|
||
| client.on('error', errorMustCall); | ||
| req.on('error', errorMustNotCall); | ||
|
|
||
| req.on('end', common.mustCall(() => { | ||
| client.destroy(); | ||
| if (!tests.length) { | ||
| server.close(); | ||
| } else { | ||
| runTest(tests.shift()); | ||
| } | ||
| })); | ||
| } |
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
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.
I'm not sure I'm following what's going on with the changes in this file. Is there a reason everything needs to be scoped within the stream handler? This looks like a lot of churn and I'm having trouble following why.
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.
I originally started working on this file and formatted the code using Prettier.
I created
test-http2-client-settings-errors.jsafter coming across the template used by other tests which checked for errors.I've scoped method
assertSettingswithin stream handler, as it's only used within that block.Uh oh!
There was an error while loading. Please reload this page.
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.
My concern is just that it's a bit easier to follow the file history (
git blame) when changes aren't made just for the sake of changing code style, unless the clarity is a significant problem. That said, this is a nit so if no one else cares then this is fine. Thanks for the explanation 👍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.
I agree that code change shouldn't be made just for changing code style.
I added changed in
test-http2-session-settings.jsas the formatting was already done. I'll remove it from the commit if more people raise it in the reviews.Btw, I created an issue at #16115 to check if we can move to Javascript formatter like Prettier.