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

Additional fetch abort tests #6736

Merged
merged 9 commits into from
Aug 14, 2017
Merged
35 changes: 35 additions & 0 deletions fetch/api/abort/general.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,38 @@ promise_test(async t => {

assert_equals(cancelReason, fetchErr, "Fetch rejects with same error instance");
}, "Readable stream synchronously cancels with AbortError if aborted before reading");

test(() => {
const controller = new AbortController();
const signal = controller.signal;
controller.abort();

const request = new Request('.', { signal });
const requestSignal = request.signal;

const clonedRequest = request.clone();

assert_equals(requestSignal, request.signal, "Original request signal the same after cloning");
assert_true(request.signal.aborted, "Original request signal aborted");
assert_not_equals(clonedRequest.signal, request.signal, "Cloned request has different signal");
assert_true(clonedRequest.signal.aborted, "Cloned request signal aborted");
}, "Signal state is cloned");

test(() => {
const controller = new AbortController();
const signal = controller.signal;

const request = new Request('.', { signal });
const clonedRequest = request.clone();

let requestAborted = false;
let clonedRequestAborted = false;

request.signal.addEventListener('abort', () => requestAborted = true);
clonedRequest.signal.addEventListener('abort', () => clonedRequestAborted = true);

controller.abort();

assert_true(requestAborted, "Original request signal aborted");
Copy link
Member

Choose a reason for hiding this comment

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

This assert could be inside the clonedRequest.signal event listener. That way we also verify that the order is correct. Should we also check here that for both the .aborted flag is flipped?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I move the tests within the event callbacks then failure to call those callbacks will look like success. I guess I could push items onto an array to check order too.

Copy link
Member

Choose a reason for hiding this comment

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

You could also use a signal variable that you change in the first listener and that you then assert has changed in the second listener and then change again and then assert it has changed after that listener.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From IRC: As spec'd, the clone's abort event would run before the original's. We need to figure out if this is a problem. If it is, we could change the AbortSignal spec so it has a list of "following signals", which copy things that happen to the original, but it happens after the original's event has despatched.

assert_true(clonedRequestAborted, "Cloned request signal aborted");
}, "Clone aborts with original controller");