diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-03-08 04:45:25 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-03-08 04:45:25 +0530 |
commit | fee7cb179ee7ba2f159d87af07afaf0cd99a2161 (patch) | |
tree | 42d7ff160f68ab0f2deaa7988e3cdc9b8735e91b /tests/unit/net/fetch.rs | |
parent | 7308205bfc15f217d80dd2fc9995531bcea77d00 (diff) | |
parent | b187985e4967c2ccb6c951a68b7c0916caa16bb4 (diff) | |
download | servo-fee7cb179ee7ba2f159d87af07afaf0cd99a2161.tar.gz servo-fee7cb179ee7ba2f159d87af07afaf0cd99a2161.zip |
Auto merge of #9850 - nikkisquared:2_async_2_furious, r=jdm
Set response.body Asynchronously In Fetch
Following having finished making Fetch asynchronous, response.body should be set asynchronously, since it's the major goal of calling Fetch. So far, I've made the body wrapped in Arc<Mutex<>>, and I've wrapped a new thread around the part where it's set. I've also discovered that the fetch_async function makes step 8 of Main Fetch obsolete, and I've commented it appropriately.
I'm currently having a hard time with the thread for setting response.body, though. @jdm suggested I have the body set continually, block by block, but my implementation for that runs so slow that I can't finish running my fetch test suite in reasonable time. @KiChjang pointed out that a lot of the lag is due to how response.body currently stores everything inside a Vec. Changing the storage container seems to be both necessary and beyond the scope of the time I have to work on this.
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9850)
<!-- Reviewable:end -->
Diffstat (limited to 'tests/unit/net/fetch.rs')
-rw-r--r-- | tests/unit/net/fetch.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/tests/unit/net/fetch.rs b/tests/unit/net/fetch.rs index 8fcd5b95dbd..e881d8b24a7 100644 --- a/tests/unit/net/fetch.rs +++ b/tests/unit/net/fetch.rs @@ -88,7 +88,7 @@ fn test_fetch_response_body_matches_const_message() { assert!(!fetch_response.is_network_error()); assert_eq!(fetch_response.response_type, ResponseType::Basic); - match *fetch_response.body.borrow() { + match *fetch_response.body.lock().unwrap() { ResponseBody::Done(ref body) => { assert_eq!(&**body, MESSAGE); }, @@ -210,7 +210,7 @@ fn test_fetch_response_is_opaque_filtered() { // this also asserts that status message is "the empty byte sequence" assert!(fetch_response.status.is_none()); assert_eq!(fetch_response.headers, Headers::new()); - match fetch_response.body.into_inner() { + match *fetch_response.body.lock().unwrap() { ResponseBody::Empty => { }, _ => panic!() } @@ -260,7 +260,7 @@ fn test_fetch_response_is_opaque_redirect_filtered() { // this also asserts that status message is "the empty byte sequence" assert!(fetch_response.status.is_none()); assert_eq!(fetch_response.headers, Headers::new()); - match fetch_response.body.into_inner() { + match *fetch_response.body.lock().unwrap() { ResponseBody::Empty => { }, _ => panic!() } @@ -315,7 +315,7 @@ fn test_fetch_redirect_count_ceiling() { assert!(!fetch_response.is_network_error()); assert_eq!(fetch_response.response_type, ResponseType::Basic); - match *fetch_response.body.borrow() { + match *fetch_response.body.lock().unwrap() { ResponseBody::Done(ref body) => { assert_eq!(&**body, MESSAGE); }, @@ -334,7 +334,7 @@ fn test_fetch_redirect_count_failure() { assert!(fetch_response.is_network_error()); - match *fetch_response.body.borrow() { + match *fetch_response.body.lock().unwrap() { ResponseBody::Done(_) | ResponseBody::Receiving(_) => panic!(), _ => { } }; @@ -438,13 +438,15 @@ fn test_fetch_redirect_updates_method() { fn response_is_done(response: &Response) -> bool { let response_complete = match response.response_type { - ResponseType::Default | ResponseType::Basic | ResponseType::CORS => response.body.borrow().is_done(), + ResponseType::Default | ResponseType::Basic | ResponseType::CORS => { + (*response.body.lock().unwrap()).is_done() + } // if the internal response cannot have a body, it shouldn't block the "done" state ResponseType::Opaque | ResponseType::OpaqueRedirect | ResponseType::Error => true }; let internal_complete = if let Some(ref res) = response.internal_response { - res.body.borrow().is_done() + res.body.lock().unwrap().is_done() } else { true }; |