Skip to content

http2: handling errors while submitting settings #16083

Description

@trivikr

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.

Activity

  1. joyeecheung commented on Oct 8, 2017

    @joyeecheung
    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.

  2. joyeecheung commented on Oct 8, 2017

    @joyeecheung
    Member

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

  3. trivikr commented on Oct 8, 2017

    @trivikr
    MemberAuthor

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

  4. joyeecheung commented on Oct 8, 2017

    @joyeecheung
    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

  5. trivikr commented on Oct 8, 2017

    @trivikr
    MemberAuthor

    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;

  6. joyeecheung commented on Oct 8, 2017

    @joyeecheung
    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.

  7. trivikr commented on Oct 8, 2017

    @trivikr
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues asking questions about Node.js.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions