mirror of
https://github.com/servo/servo.git
synced 2025-08-01 11:40:30 +01:00
Instead of creating a `ROUTER` for each fetch, create a fetch thread which handles all incoming and outcoming fetch requests. Now messages involving fetches carry a "request id" which indicates which fetch is being addressed by the message. This greatly reduces the number of file descriptors used by fetch. In addition, the interface for kicking off fetches is simplified when using the `Listener` with `Document`s and the `GlobalScope`. This does not fix all leaked file descriptors / mach ports, but greatly eliminates the number used. Now tests can be run without limiting procesess on modern macOS systems. Followup work: 1. There are more instances where fetch is done using the old method. Some of these require more changes in order to be converted to the `FetchThread` approach. 2. Eliminate usage of IPC channels when doing redirects. 3. Also eliminate the IPC channel used for cancel handling. 4. This change opens up the possiblity of controlling the priority of fetch requests. Fixes #29834. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
50 lines
2.1 KiB
Rust
50 lines
2.1 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* 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 base::id::TEST_PIPELINE_ID;
|
|
use http::header::{HeaderValue, EXPIRES};
|
|
use http::StatusCode;
|
|
use net::http_cache::HttpCache;
|
|
use net_traits::request::{Referrer, RequestBuilder};
|
|
use net_traits::response::{Response, ResponseBody};
|
|
use net_traits::{ResourceFetchTiming, ResourceTimingType};
|
|
use servo_url::ServoUrl;
|
|
use tokio::sync::mpsc::unbounded_channel as unbounded;
|
|
|
|
#[test]
|
|
fn test_refreshing_resource_sets_done_chan_the_appropriate_value() {
|
|
let response_bodies = vec![
|
|
ResponseBody::Receiving(vec![]),
|
|
ResponseBody::Empty,
|
|
ResponseBody::Done(vec![]),
|
|
];
|
|
let url = ServoUrl::parse("https://servo.org").unwrap();
|
|
let request = RequestBuilder::new(url.clone(), Referrer::NoReferrer)
|
|
.pipeline_id(Some(TEST_PIPELINE_ID))
|
|
.origin(url.origin())
|
|
.build();
|
|
let timing = ResourceFetchTiming::new(ResourceTimingType::Navigation);
|
|
let mut response = Response::new(url.clone(), timing);
|
|
// Expires header makes the response cacheable.
|
|
response
|
|
.headers
|
|
.insert(EXPIRES, HeaderValue::from_str("-10").unwrap());
|
|
let mut cache = HttpCache::default();
|
|
response_bodies.iter().for_each(|body| {
|
|
*response.body.lock().unwrap() = body.clone();
|
|
// First, store the 'normal' response.
|
|
cache.store(&request, &response);
|
|
// Second, mutate the response into a 304 response, and refresh the stored one.
|
|
response.status = StatusCode::NOT_MODIFIED.into();
|
|
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());
|
|
match body {
|
|
ResponseBody::Receiving(_) => assert!(done_chan.is_some()),
|
|
ResponseBody::Empty | ResponseBody::Done(_) => assert!(done_chan.is_none()),
|
|
}
|
|
})
|
|
}
|