Skip to content
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

http2: handling errors while submitting settings #16083

Closed
trivikr opened this issue Oct 8, 2017 · 7 comments
Closed

http2: handling errors while submitting settings #16083

trivikr opened this issue Oct 8, 2017 · 7 comments
Labels
question Issues that look for answers.

Comments

@trivikr
Copy link
Member

trivikr commented Oct 8, 2017

As part of improving http2 test coverage in #14985, I was trying to unit test the following code in submitSettings()

switch (ret) {
case NGHTTP2_ERR_NOMEM:
err = new errors.Error('ERR_OUTOFMEMORY');
process.nextTick(emit, this, 'error', err);
break;
default:
// Some other unexpected error was reported.
if (ret < 0) {
err = new NghttpError(ret);
process.nextTick(emit, this, 'error', err);
}
}

While debugging, I'm not able to step into handle.submitSettings() to check how the value of ret is computed
screen shot 2017-10-07 at 10 01 07 pm

I don't see method submitSettings for handle in the call stack.
This appears to be an issue. Am I missing something? I'm testing on node master branch.

@joyeecheung
Copy link
Member

@trivikr In the JS codebase usually the method in handle.method is defined in the C++ land. In this case it is defined in node_http2.cc (

void Http2Session::SubmitSettings(const FunctionCallbackInfo<Value>& args) {
), so the devtools won't be able to step into that, it's normal. If you do want to debug the C++ code, you can try attaching debuggers like gdb or lldb to your running process and set a breakpoint in that C++ method.

@joyeecheung
Copy link
Member

I will close this since this is not a bug, but feel free to discuss or ask questions in this thread.

@joyeecheung joyeecheung added the question Issues that look for answers. label Oct 8, 2017
@trivikr
Copy link
Member Author

trivikr commented Oct 8, 2017

Thanks @joyeecheung
Is there some example I can refer to check how C++ methods are mocked while testing in Javascript?

@joyeecheung
Copy link
Member

@trivikr Sorry, I am not sure if I am following what "how C++ methods are mocked" means. If you want to know how the C++ glue code works, taking a look at the v8 Embedder's Guide would help

@trivikr
Copy link
Member Author

trivikr commented Oct 8, 2017

Hi @joyeecheung, while writing unit tests in Javascript we sometimes mock functions as we've to test particular file and not it's dependencies.

I came across a code which mocks C++ methods in Javascript at

// mock submitPriority because we only care about testing error handling
Http2Session.prototype.submitPriority = () => currentError.ngError;

@joyeecheung
Copy link
Member

@trivikr I don't work with HTTP2 tests but I think you can just do something like what the code that you have posted does, and mock submitSetting to return values that can get you into the branches you want to cover.

@trivikr
Copy link
Member Author

trivikr commented Oct 8, 2017

Yes, I'm using the following line for mocking submitSettings
Http2Session.prototype.submitSettings = () => constants.NGHTTP2_ERR_NOMEM;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

2 participants