Skip to content

Commit ccb103b

Browse files
kinnisonEduard Miller
authored andcommitted
download: Serialise proxy environment tests
In order to ensure that we do not stomp on each other when running tests in the download crate to verify proxy behaviour, introduce a Mutex to guard against this. Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
1 parent beb8aa4 commit ccb103b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

download/tests/read-proxy-env.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ use std::env::{remove_var, set_var};
44
use std::error::Error;
55
use std::net::TcpListener;
66
use std::sync::atomic::{AtomicUsize, Ordering};
7+
use std::sync::Mutex;
78
use std::thread;
89
use std::time::Duration;
910

1011
use env_proxy::for_url;
12+
use lazy_static::lazy_static;
1113
use reqwest::{blocking::Client, Proxy};
1214
use url::Url;
1315

16+
lazy_static! {
17+
static ref SERIALISE_TESTS: Mutex<()> = Mutex::new(());
18+
}
19+
1420
fn scrub_env() {
1521
remove_var("http_proxy");
1622
remove_var("https_proxy");
@@ -26,6 +32,9 @@ fn scrub_env() {
2632
// Tests for correctly retrieving the proxy (host, port) tuple from $https_proxy
2733
#[test]
2834
fn read_basic_proxy_params() {
35+
let _guard = SERIALISE_TESTS
36+
.lock()
37+
.expect("Unable to lock the test guard");
2938
scrub_env();
3039
set_var("https_proxy", "http://proxy.example.com:8080");
3140
let u = Url::parse("https://www.example.org").ok().unwrap();
@@ -39,6 +48,9 @@ fn read_basic_proxy_params() {
3948
#[test]
4049
fn socks_proxy_request() {
4150
static CALL_COUNT: AtomicUsize = AtomicUsize::new(0);
51+
let _guard = SERIALISE_TESTS
52+
.lock()
53+
.expect("Unable to lock the test guard");
4254

4355
scrub_env();
4456
set_var("all_proxy", "socks5://127.0.0.1:1080");

0 commit comments

Comments
 (0)