-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Fetch: Add tests for AbortSignal's abort reason #35374
Fetch: Add tests for AbortSignal's abort reason #35374
Conversation
The added cases look good. I think we should test that the service worker can observe the fetch abort and see the contents of the abort reason. |
I added a new test for this case, so hopefully it's looking better :) PTAL. Thank you! |
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.
LGTM, thank you!
I'm missing a test that shows that the serialization happens on abort. |
Apologies for the delay! I added a test, but I'm not sure if it's exactly what you were looking for. Would you be able to take a look? Thank you! |
This is a follow-up to whatwg/dom#1027 ensuring that the fetch algorithm forwards the abort reason appropriately. Tests: web-platform-tests/wpt#35374.
const controller = new w.AbortController(); | ||
const signal = controller.signal; | ||
|
||
const fetchPromise = await w.fetch('data.json', { signal }); |
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.
The test does not produce the required failure messages in the tests
I think the await here should be removed.
The above code will return a response object and not the promise which we need to pass it to promise_rejects_exactly.
The following code should solve the problem:
const fetchPromise = w.fetch('data.json', { signal });
Kindly check, I am not a JS expert :)
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.
That seems correct @MayyaSunil. Could you create a PR?
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.
Sure @annevk. I will submit the fix in mozilla's repo and let the sync bot do the job? Is it acceptable to you?
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.
Yeah that works. It might be worth having another test like this whereby we do wait for the response and then check that response.body
was errored with the correct exception if that doesn't exist already.
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.
Bug 1798921 is created to track this
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.
If the below patch is fine, I will submit it to our repo.
--- a/testing/web-platform/tests/fetch/api/abort/serviceworker-intercepted.https.html
+++ b/testing/web-platform/tests/fetch/api/abort/serviceworker-intercepted.https.html
@@ -114,13 +114,31 @@
const controller = new w.AbortController();
const signal = controller.signal;
- const fetchPromise = await w.fetch('data.json', { signal });
+ const fetchPromise = w.fetch('data.json', { signal });
controller.abort(error1);
await promise_rejects_exactly(t, error1, fetchPromise);
}, "fetch() rejects with abort reason");
+
+ promise_test(async t => {
+ const scope = SCOPE + "?q=aborted-with-abort-reason-in-body";
+ await setupRegistration(t, scope, '../resources/sw-intercept.js');
+ const iframe = await with_iframe(scope);
+ add_completion_callback(_ => iframe.remove());
+ const w = iframe.contentWindow;
+
+ const controller = new w.AbortController();
+ const signal = controller.signal;
+
+ const fetchResponse = await w.fetch('data.json', { signal });
+ const bodyPromise = fetchResponse.body.getReader().read();
+ controller.abort(error1);
+
+ await promise_rejects_exactly(t, error1, bodyPromise);
+ }, "fetch() response body has abort reason");
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.
That looks correct, yeah. Thanks @MayyaSunil!
This PR adds test cases to check the functionality of AbortSignal's abort reason when aborting fetch.
See whatwg/fetch#1343 for accompanying spec changes.