-
Notifications
You must be signed in to change notification settings - Fork 96
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
Ensure callback not called when request aborted #153
Ensure callback not called when request aborted #153
Conversation
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.
Am I right that if you abort asynchronously you will get the callback again?
@naugtur, do you mean, something like this? test("aborting XHR prevents callback from being called", { timeout: 500 }, function(assert) {
var req = xhr({ uri: "/mock/200ok" }, function(err, response) {
assert.fail('this callback should not be called');
});
setTimeout(function() {
req.abort();
assert.end()
}, 0)
}) This test still passes. I think this would depend entirely upon how long the server response takes and when you call I believe the core issue was that the Does this answer your q? |
Yes, that's it. Would you mind adding that as a test too? |
Yep no problem, added. |
Hmmm, I'm not sure why that failed in CI, I'm able to see it pass consistently locally. It might have to do with the mock server response time being faster in CI than on my machine. I'll have to look into this some more. |
I wonder if there is a way to delay the mock server's response by a fixed amount, say 50ms. Otherwise I'm not sure this second test, the async abort, is very helpful, because it might sometimes pass and sometimes fail, depending on the environment. |
I had not looked at the mock server...so I swapped in the "timeout" endpoint to simulate a more realistic server response time rather than immediate, like the 200 ok endpoint. This works! |
When the xhr is aborted programmatically, the callback should not be called, but it still is. This patch prevents that.
Related to #93, #104