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

Add a fetch test for upload streaming #4362

Merged
merged 4 commits into from
Jan 7, 2017
Merged

Add a fetch test for upload streaming #4362

merged 4 commits into from
Jan 7, 2017

Conversation

yutakahirano
Copy link
Contributor

Adding a test for uploading a request made from a ReadableStream.

@wpt-pr-bot
Copy link
Collaborator

Notifying @jdm and @youennf. (Learn how reviewing works.)

@yutakahirano
Copy link
Contributor Author

@annevk: This is for whatwg/fetch#425

@annevk
Copy link
Member

annevk commented Dec 19, 2016

This looks okay to me. Though ideally we also have some tests around redirect handling and different kinds of methods. For a new feature that will need tests written anyway as part of the implementation this might be good enough though.

@foolip @domenic thoughts?

@foolip
Copy link
Member

foolip commented Dec 19, 2016

Yeah, testing non-trivial things blindly is very hard, and a good reason to not write all tests up front. Keeping track somewhere of what testing coverage is missing would be nice of course, but only if someone is then using that to guide testing priorities.

@domenic
Copy link
Member

domenic commented Dec 19, 2016

Wait, we're allowing strings to be enqueued? I didn't get that from whatwg/fetch#425 .

@annevk
Copy link
Member

annevk commented Dec 19, 2016

That is a good point and needs to be fixed in the test.

Where do we currently place restrictions on what can be on a ReadableStream object used in Fetch? It seems like we don't...

@yutakahirano
Copy link
Contributor Author

Wait, we're allowing strings to be enqueued? I didn't get that from whatwg/fetch#425 .

Sorry that was my mistake. Fixed.

Where do we currently place restrictions on what can be on a ReadableStream object used in Fetch? It seems like we don't...

At least, Request.text(), etc. expect that as they are using https://fetch.spec.whatwg.org/#concept-read-all-bytes-from-readablestream.

@annevk
Copy link
Member

annevk commented Dec 19, 2016

We should also make the network layer expect that though. And whatever ends up reading a response.

@yutakahirano
Copy link
Contributor Author

@annevk
Copy link
Member

annevk commented Dec 19, 2016

Yeah I suppose. And we probably need something similar for responses then and make sure all specifications use it… 😟

@annevk
Copy link
Member

annevk commented Dec 19, 2016

I'm not sure what you're asking for.

@guest271314
Copy link
Contributor

guest271314 commented Dec 19, 2016

@annevk Tried to run the current test in browser at http://w3c-test.org/tools/runner/index.html. Checked all fetch tests, browser crashed at a worker test. Just want to run the current test. How to do this at *nix, chromium 52?

@annevk
Copy link
Member

annevk commented Dec 19, 2016

What current test? This is a pull request for a test change. It hasn't landed...

@guest271314
Copy link
Contributor

guest271314 commented Dec 19, 2016

@annevk This test https://github.com/w3c/web-platform-tests/pull/4362/files/3a994b7107795de307eb7039676e130fbf11d9e9..54138da06de3bca241195f1459ae863b4ade77e8. Not well-versed in the terminology and mechanics of git, pull requests. Is it not currently possible to try this now? Is a "pull request" code written that is tested before being published at large?

@annevk
Copy link
Member

annevk commented Dec 19, 2016

You can locally check out the code and run it. I believe for some PRs there's also a URL you can visit, but not for this PR it seems (might depend on where the branch is situated).

@guest271314
Copy link
Contributor

guest271314 commented Dec 19, 2016

@annevk Is the above referenced test in that repository? Do not need to run all of the tests in the repo, just the newest one, or only the fetch tests. Is it necessary to download the entire repo? And install the python server? Was there changes made to the way fetch body functions in order to pass the test? Perhaps beyond the scope of this topic, though am trying to learn more about this part of programming. This is the only experience have so far with this part of programming https://github.com/guest271314/jquery-3.0.0-promises-tests-in-browser , http://stackoverflow.com/questions/36438228/how-to-test-if-jquery-3-0-beta-is-promises-a-compatible-in-browser/

@annevk
Copy link
Member

annevk commented Dec 19, 2016

The test of this PR is in https://github.com/yutakahirano/web-platform-tests/tree/upload-streaming, a branch in a fork of this repository. If you just want to know whether any browser passes the test, I can tell you that none do, since as I told you elsewhere, this is not implemented yet.

@guest271314
Copy link
Contributor

guest271314 commented Dec 19, 2016

@annevk Am attempting to gain more knowledge about the entire process. Your feedback has been helpful.

annevk pushed a commit to whatwg/fetch that referenced this pull request Jan 5, 2017
Basic test: web-platform-tests/wpt#4362. More tests are expected to be written as part of the implementation effort.

Further work: #441.

Fixes #88.
@annevk
Copy link
Member

annevk commented Jan 5, 2017

@yutakahirano perhaps you can also add a test that expects strings and numbers and such to fail.

@yutakahirano
Copy link
Contributor Author

@yutakahirano perhaps you can also add a test that expects strings and numbers and such to fail.

Done.

@annevk
Copy link
Member

annevk commented Jan 5, 2017

Thanks, @domenic could you give it another review?

@annevk annevk requested a review from domenic January 5, 2017 12:44
Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

Some minor test nits. Additionally I have something I am confused about; forgive me if we have discussed it before.

These tests seem to imply that fetch() will read the whole request body stream before fulfilling or rejecting the fetch promise. But, doesn't that hurt our ability to do full-duplex communication with streams? I thought the idea was that you could pass a request body stream, and get back a response body stream, and use them both at the same time. If we wait for the request body stream to be fully read before vending the response body stream, this is not possible, right?

body = body();
if (body)
requestInit["body"] = body;
return fetch(url, requestInit).then(() => {
Copy link
Member

Choose a reason for hiding this comment

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

This should use return promise_rejects(new TypeError(), fetch(url, requestInit))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

testUploadFailure("Fetch with POST with ReadableStream containing number", url, "POST", new ReadableStream({start: controller => {
controller.enqueue(99);
controller.close();
}}));
Copy link
Member

Choose a reason for hiding this comment

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

We should also test ArrayBuffer and Blob are not allowed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@annevk
Copy link
Member

annevk commented Jan 5, 2017

I agree with your assessment of how things should be with regards to full-duplex communication. These tests are simply not testing that scenario, or am I missing something?

@domenic
Copy link
Member

domenic commented Jan 5, 2017

Well, these tests assert bad data causes a rejected promise. How is that possible unless you read to the end before delivering the response?

With full duplex you should be able to get a fulfilled promise (with a response you can read from) even if the request contains bad data. Maybe there's a race there and this test is assuming the race resolves in favor of terminating due to bad data before the response is vended?

@annevk
Copy link
Member

annevk commented Jan 5, 2017

I would expect that the default server setup is such that it doesn't emit a response before getting the full request body. It would be good to have tests for early transmitted responses though.

@domenic
Copy link
Member

domenic commented Jan 5, 2017

I see. So is the intent of the spec that there's a race then? If the fetch gets terminated before the promise settles, then the promise is rejected (as in this case); if the fetch gets terminated after the response comes back, the promise is still fulfilled?

@annevk
Copy link
Member

annevk commented Jan 5, 2017

Yeah, the fetch gets terminated so you might not get the whole response body. We should really figure out a way to write full duplex tests since I suspect it is all kinds of broken.

@domenic
Copy link
Member

domenic commented Jan 5, 2017

OK, if that's intended then the tests are good, just the nits in my review remaining.

@annevk annevk merged commit 1dd5361 into web-platform-tests:master Jan 7, 2017
annevk pushed a commit to whatwg/fetch that referenced this pull request Jan 17, 2017
Basic tests: web-platform-tests/wpt#4362. More tests are expected to be written as part of the implementation effort.

Fixes #88, fixes yutakahirano/fetch-with-streams#10, fixes yutakahirano/fetch-with-streams#57, and fixes yutakahirano/fetch-with-streams#66.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants