From 57b6659957336375192eabb38ab4db2f0ccd428f Mon Sep 17 00:00:00 2001 From: Florent 'Skia' Jacquet Date: Wed, 10 Jul 2024 12:18:53 +0200 Subject: [PATCH 1/2] tests: bypass the proxy when testing timeouts If an explicit proxy is configured in the environment, the timeout tests will actually go through it, and then the test results will depend on the proxy's performance, which can vary. Testing this is very simple: ``` export http_proxy="http://127.0.0.1:1234" cargo test timeouts ``` We're hitting this issue in the Ubuntu CI. Further investigations after 892569e10b69d1a0e5db1f53202d1ebf09924fc1 seemed to point that **sometimes**, the proxy would be too slow (particularly on non amd64 architectures), leading to the tests to actually timeout and pass. --- tests/timeouts.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/timeouts.rs b/tests/timeouts.rs index c3649ea9f..410d722f4 100644 --- a/tests/timeouts.rs +++ b/tests/timeouts.rs @@ -19,6 +19,7 @@ async fn client_timeout() { let client = reqwest::Client::builder() .timeout(Duration::from_millis(100)) + .no_proxy() .build() .unwrap(); @@ -44,7 +45,7 @@ async fn request_timeout() { } }); - let client = reqwest::Client::builder().build().unwrap(); + let client = reqwest::Client::builder().no_proxy().build().unwrap(); let url = format!("http://{}/slow", server.addr()); @@ -71,6 +72,7 @@ async fn connect_timeout() { let client = reqwest::Client::builder() .connect_timeout(Duration::from_millis(100)) + .no_proxy() .build() .unwrap(); @@ -101,6 +103,7 @@ async fn connect_many_timeout_succeeds() { &["10.255.255.1:81".parse().unwrap(), server.addr()], ) .connect_timeout(Duration::from_millis(100)) + .no_proxy() .build() .unwrap(); @@ -128,6 +131,7 @@ async fn connect_many_timeout() { ], ) .connect_timeout(Duration::from_millis(100)) + .no_proxy() .build() .unwrap(); @@ -190,6 +194,7 @@ async fn read_timeout_applies_to_headers() { let client = reqwest::Client::builder() .read_timeout(Duration::from_millis(100)) + .no_proxy() .build() .unwrap(); @@ -410,7 +415,7 @@ async fn response_body_timeout_forwards_size_hint() { let server = server::http(move |_req| async { http::Response::new(b"hello".to_vec().into()) }); - let client = reqwest::Client::new(); + let client = reqwest::Client::builder().no_proxy().build().unwrap(); let url = format!("http://{}/slow", server.addr()); From 342d2cdeed462684377a292496ac45f1f4c44a70 Mon Sep 17 00:00:00 2001 From: Florent 'Skia' Jacquet Date: Wed, 11 Sep 2024 16:13:45 +0200 Subject: [PATCH 2/2] tests: use a documented test network for testing 10.255.255.0/24 is part of 10.0.0.0/8 and reserved for "Private Use" by IANA [1]. That means that those IP might be in use in some internal networks, making the timeout tests to fail on those networks. One example of such network is the Ubuntu testing infrastructure. Changing for a documented "Test network", that is supposed to never be routable [2] makes the tests to have a better chance to pass in most network contexts. [1]: https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml [2]: https://www.rfc-editor.org/rfc/rfc5737.html --- tests/timeouts.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/timeouts.rs b/tests/timeouts.rs index 410d722f4..79a6fbb4d 100644 --- a/tests/timeouts.rs +++ b/tests/timeouts.rs @@ -76,7 +76,7 @@ async fn connect_timeout() { .build() .unwrap(); - let url = "http://10.255.255.1:81/slow"; + let url = "http://192.0.2.1:81/slow"; let res = client .get(url) @@ -100,7 +100,7 @@ async fn connect_many_timeout_succeeds() { let client = reqwest::Client::builder() .resolve_to_addrs( "many_addrs", - &["10.255.255.1:81".parse().unwrap(), server.addr()], + &["192.0.2.1:81".parse().unwrap(), server.addr()], ) .connect_timeout(Duration::from_millis(100)) .no_proxy() @@ -126,8 +126,8 @@ async fn connect_many_timeout() { .resolve_to_addrs( "many_addrs", &[ - "10.255.255.1:81".parse().unwrap(), - "10.255.255.2:81".parse().unwrap(), + "192.0.2.1:81".parse().unwrap(), + "192.0.2.2:81".parse().unwrap(), ], ) .connect_timeout(Duration::from_millis(100))