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

Do not abort a an already aborted request, do not emit an error twice #886

Merged
merged 1 commit into from
Sep 23, 2017

Conversation

nknapp
Copy link
Contributor

@nknapp nknapp commented Apr 21, 2017

Fixes #882

When a request is aborted, "nock" emits an "abort"-error.
If the client reacts on that error by aborting the request (this is what
"popsicle" does), the code will end in an endless loop.
This commit makes that the the "abort"-code is only executed, if the
request has not already been aborted.

@nknapp
Copy link
Contributor Author

nknapp commented Apr 21, 2017

I have test-failures on my local machine, but they also occur without this commit.
I have committed with git commit -n in order to skip tests on checkin.

Let's see, if the tests pass in travis

@coveralls
Copy link

coveralls commented Apr 21, 2017

Coverage Status

Coverage decreased (-0.06%) to 92.626% when pulling fa035f8 on bootprint:master into f268187 on node-nock:master.

@nknapp
Copy link
Contributor Author

nknapp commented Apr 21, 2017

I have to check, why my new code is not covered by the test. It should be.

@nknapp nknapp force-pushed the master branch 2 times, most recently from 1dd1aa2 to ba3fbc6 Compare April 21, 2017 06:43
@coveralls
Copy link

coveralls commented Apr 21, 2017

Coverage Status

Coverage increased (+0.01%) to 92.697% when pulling ba3fbc6 on bootprint:master into f268187 on node-nock:master.

@coveralls
Copy link

coveralls commented Apr 21, 2017

Coverage Status

Coverage increased (+0.01%) to 92.697% when pulling ba3fbc6 on bootprint:master into f268187 on node-nock:master.

@nknapp
Copy link
Contributor Author

nknapp commented Apr 21, 2017

I think, it is ready now...

@ianwsperber ianwsperber self-requested a review May 1, 2017 17:58
Copy link
Contributor

@ianwsperber ianwsperber left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to do this @nknapp! Please respond to comments when possible and maybe we can get this shipped this week.

@@ -57,3 +57,28 @@ test("abort is emitted before delay time", function(t) {
req.abort();
}, 10);
});

test("nock#882: Aborting an aborted request should not emit an error", function(t) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to include the issue number

setTimeout(function() {
t.equal(errorCount, 1,"Only one error should be sent.");
t.end();
},10);
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems brittle, since it relies on timing. Can we use req.on("end", () => { ... }) instead? That has the advantage of also asserting the request was completed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried that and got a test unfinished. It seems like the 'end'-event is not in this case. I also tried piping the response to a writable stream to make sure that the response is

Is an end-event supposed to be sent, when a request is aborted? But if "yes", then it would certainly be sent after the first abort, and not after the second one. In that case, the test could pass, even if the issue wasn't fixed, because it could happen that the t.equal-check is evaluated too early.

I think it is safer to use 'setTimeout` in this case.

@nknapp
Copy link
Contributor Author

nknapp commented May 3, 2017

I'll see to it, but probably not this week. I'll be travelling for the next couple of days and I don't know when I will find the time.

Fixes nock#882

When a request is aborted, "nock" emits an "abort"-error.
If the client reacts on that error by aborting the request (this is what
"popsicle" does), the code will end in an endless loop.
This commit makes that the the "abort"-code is only executed, if the
request has not already been aborted.
@nknapp
Copy link
Contributor Author

nknapp commented Jun 7, 2017

I have removed the issue number from the test, and another unused statement.
I have not changed the ckeck in the setTimeout. I couldn't make it work that way (and I think it is not possible to do it without using setTimeout.

I don't think that the build errors in Travis are related to my changes.

@coveralls
Copy link

coveralls commented Jun 7, 2017

Coverage Status

Coverage increased (+0.01%) to 92.697% when pulling 816e8ec on bootprint:master into 17d7c25 on node-nock:master.

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

5 participants