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

Have aborts follow the published API #1134

Merged
merged 1 commit into from Jun 7, 2018
Merged

Have aborts follow the published API #1134

merged 1 commit into from Jun 7, 2018

Conversation

allenluce
Copy link
Contributor

I had some difficulty with this code:

httpRequest.on('timeout', function () {
  trackFailure('timeout')
  httpRequest.abort()
})

httpRequest.on('error', function (err) {
  // Count error if request wasn't aborted due to timeout
  if (!httpRequest.aborted) {
    trackFailure(err)
  }
  callback(err)
}

When nock was not in use, trackFailure() would be called once on timeout. With nock enabled, trackFailure() would be called twice because httpRequest.aborted would be undefined.

This change creates and uses the aborted property in the same fashion as the system http module.

@allenluce
Copy link
Contributor Author

The Travis CI failure doesn't look like it's related to my changes:

npm ERR! Linux 4.4.0-101-generic
npm ERR! argv "/home/travis/.nvm/versions/node/v4.9.1/bin/node" "/home/travis/.nvm/versions/node/v4.9.1/bin/npm" "install"
npm ERR! node v4.9.1
npm ERR! npm  v2.15.11
npm ERR! code EPEERINVALID
npm ERR! peerinvalid The package marked@0.4.0 does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer marked-terminal@2.0.0 wants marked@^0.3.6

I had some difficulty with this code:

    httpRequest.on('timeout', function () {
      trackFailure('timeout')
      httpRequest.abort()
    })

    httpRequest.on('error', function (err) {
      // Count error if request wasn't aborted due to timeout
      if (!httpRequest.aborted) {
        trackFailure(err)
      }
      callback(err)
    }

When `nock` was not in use, `trackFailure()` would be called once on
timeout.  With `nock` enabled, `trackFailure()` would be called twice
because `httpRequest.aborted` would be undefined.

This change creates and uses the `aborted` property in the same
fashion as the system `http` module.
@allenluce
Copy link
Contributor Author

I've rebased this on the current master, looks like that took care of the test failures.

Copy link
Member

@gr2m gr2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good 👍

@gr2m gr2m merged commit aaa9a56 into nock:master Jun 7, 2018
@nockbot
Copy link
Collaborator

nockbot commented Jun 7, 2018

🎉 This PR is included in version 9.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lock
Copy link

lock bot commented Sep 13, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!

@lock lock bot locked as resolved and limited conversation to collaborators Sep 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants