mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Non-blocking network IO
This commit is contained in:
parent
f77e66bbf8
commit
903e0cd857
13 changed files with 475 additions and 345 deletions
|
@ -48,6 +48,7 @@ use std::path::Path;
|
|||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::{Arc, Mutex, Weak};
|
||||
use std::time::{Duration, SystemTime};
|
||||
use tokio_test::block_on;
|
||||
use uuid::Uuid;
|
||||
|
||||
// TODO write a struct that impls Handler for storing test values
|
||||
|
@ -191,9 +192,12 @@ fn test_fetch_blob() {
|
|||
let origin = ServoUrl::parse("http://www.example.org/").unwrap();
|
||||
|
||||
let id = Uuid::new_v4();
|
||||
context
|
||||
.filemanager
|
||||
.promote_memory(id.clone(), blob_buf, true, "http://www.example.org".into());
|
||||
context.filemanager.lock().unwrap().promote_memory(
|
||||
id.clone(),
|
||||
blob_buf,
|
||||
true,
|
||||
"http://www.example.org".into(),
|
||||
);
|
||||
let url = ServoUrl::parse(&format!("blob:{}{}", origin.as_str(), id.to_simple())).unwrap();
|
||||
|
||||
let mut request = Request::new(
|
||||
|
@ -212,7 +216,7 @@ fn test_fetch_blob() {
|
|||
expected: bytes.to_vec(),
|
||||
};
|
||||
|
||||
methods::fetch(&mut request, &mut target, &context);
|
||||
block_on(methods::fetch(&mut request, &mut target, &context));
|
||||
|
||||
let fetch_response = receiver.recv().unwrap();
|
||||
assert!(!fetch_response.is_network_error());
|
||||
|
@ -772,7 +776,10 @@ fn test_fetch_with_hsts() {
|
|||
state: Arc::new(HttpState::new(tls_config)),
|
||||
user_agent: DEFAULT_USER_AGENT.into(),
|
||||
devtools_chan: None,
|
||||
filemanager: FileManager::new(create_embedder_proxy(), Weak::new()),
|
||||
filemanager: Arc::new(Mutex::new(FileManager::new(
|
||||
create_embedder_proxy(),
|
||||
Weak::new(),
|
||||
))),
|
||||
file_token: FileTokenCheck::NotRequired,
|
||||
cancellation_listener: Arc::new(Mutex::new(CancellationListener::new(None))),
|
||||
timing: ServoArc::new(Mutex::new(ResourceFetchTiming::new(
|
||||
|
@ -835,7 +842,10 @@ fn test_load_adds_host_to_hsts_list_when_url_is_https() {
|
|||
state: Arc::new(HttpState::new(tls_config)),
|
||||
user_agent: DEFAULT_USER_AGENT.into(),
|
||||
devtools_chan: None,
|
||||
filemanager: FileManager::new(create_embedder_proxy(), Weak::new()),
|
||||
filemanager: Arc::new(Mutex::new(FileManager::new(
|
||||
create_embedder_proxy(),
|
||||
Weak::new(),
|
||||
))),
|
||||
file_token: FileTokenCheck::NotRequired,
|
||||
cancellation_listener: Arc::new(Mutex::new(CancellationListener::new(None))),
|
||||
timing: ServoArc::new(Mutex::new(ResourceFetchTiming::new(
|
||||
|
@ -900,7 +910,10 @@ fn test_fetch_self_signed() {
|
|||
state: Arc::new(HttpState::new(tls_config)),
|
||||
user_agent: DEFAULT_USER_AGENT.into(),
|
||||
devtools_chan: None,
|
||||
filemanager: FileManager::new(create_embedder_proxy(), Weak::new()),
|
||||
filemanager: Arc::new(Mutex::new(FileManager::new(
|
||||
create_embedder_proxy(),
|
||||
Weak::new(),
|
||||
))),
|
||||
file_token: FileTokenCheck::NotRequired,
|
||||
cancellation_listener: Arc::new(Mutex::new(CancellationListener::new(None))),
|
||||
timing: ServoArc::new(Mutex::new(ResourceFetchTiming::new(
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crossbeam_channel::unbounded;
|
||||
use http::header::{HeaderValue, EXPIRES};
|
||||
use http::StatusCode;
|
||||
use msg::constellation_msg::TEST_PIPELINE_ID;
|
||||
|
@ -11,6 +10,7 @@ use net_traits::request::{Origin, Referrer, Request};
|
|||
use net_traits::response::{HttpsState, Response, ResponseBody};
|
||||
use net_traits::{ResourceFetchTiming, ResourceTimingType};
|
||||
use servo_url::ServoUrl;
|
||||
use tokio2::sync::mpsc::unbounded_channel as unbounded;
|
||||
|
||||
#[test]
|
||||
fn test_refreshing_resource_sets_done_chan_the_appropriate_value() {
|
||||
|
@ -40,7 +40,8 @@ fn test_refreshing_resource_sets_done_chan_the_appropriate_value() {
|
|||
cache.store(&request, &response);
|
||||
// Second, mutate the response into a 304 response, and refresh the stored one.
|
||||
response.status = Some((StatusCode::NOT_MODIFIED, String::from("304")));
|
||||
let mut done_chan = Some(unbounded());
|
||||
let (send, recv) = unbounded();
|
||||
let mut done_chan = Some((send, recv));
|
||||
let refreshed_response = cache.refresh(&request, response.clone(), &mut done_chan);
|
||||
// Ensure a resource was found, and refreshed.
|
||||
assert!(refreshed_response.is_some());
|
||||
|
|
|
@ -50,6 +50,7 @@ use tokio::net::TcpListener;
|
|||
use tokio::reactor::Handle;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio_openssl::SslAcceptorExt;
|
||||
use tokio_test::block_on;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref HANDLE: Mutex<Runtime> = Mutex::new(Runtime::new().unwrap());
|
||||
|
@ -103,8 +104,11 @@ fn new_fetch_context(
|
|||
FetchContext {
|
||||
state: Arc::new(HttpState::new(tls_config)),
|
||||
user_agent: DEFAULT_USER_AGENT.into(),
|
||||
devtools_chan: dc,
|
||||
filemanager: FileManager::new(sender, pool_handle.unwrap_or_else(|| Weak::new())),
|
||||
devtools_chan: dc.map(|dc| Arc::new(Mutex::new(dc))),
|
||||
filemanager: Arc::new(Mutex::new(FileManager::new(
|
||||
sender,
|
||||
pool_handle.unwrap_or_else(|| Weak::new()),
|
||||
))),
|
||||
file_token: FileTokenCheck::NotRequired,
|
||||
cancellation_listener: Arc::new(Mutex::new(CancellationListener::new(None))),
|
||||
timing: ServoArc::new(Mutex::new(ResourceFetchTiming::new(
|
||||
|
@ -131,7 +135,7 @@ fn fetch_with_context(request: &mut Request, mut context: &mut FetchContext) ->
|
|||
let (sender, receiver) = unbounded();
|
||||
let mut target = FetchResponseCollector { sender: sender };
|
||||
|
||||
methods::fetch(request, &mut target, &mut context);
|
||||
block_on(methods::fetch(request, &mut target, &mut context));
|
||||
|
||||
receiver.recv().unwrap()
|
||||
}
|
||||
|
@ -140,12 +144,12 @@ fn fetch_with_cors_cache(request: &mut Request, cache: &mut CorsCache) -> Respon
|
|||
let (sender, receiver) = unbounded();
|
||||
let mut target = FetchResponseCollector { sender: sender };
|
||||
|
||||
methods::fetch_with_cors_cache(
|
||||
block_on(methods::fetch_with_cors_cache(
|
||||
request,
|
||||
cache,
|
||||
&mut target,
|
||||
&mut new_fetch_context(None, None, None),
|
||||
);
|
||||
));
|
||||
|
||||
receiver.recv().unwrap()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue