Skip to content

Commit

Permalink
download: Serialise proxy environment tests
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kinnison authored and Eduard Miller committed Aug 31, 2020
1 parent beb8aa4 commit ccb103b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions download/tests/read-proxy-env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ use std::env::{remove_var, set_var};
use std::error::Error;
use std::net::TcpListener;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Mutex;
use std::thread;
use std::time::Duration;

use env_proxy::for_url;
use lazy_static::lazy_static;
use reqwest::{blocking::Client, Proxy};
use url::Url;

lazy_static! {
static ref SERIALISE_TESTS: Mutex<()> = Mutex::new(());
}

fn scrub_env() {
remove_var("http_proxy");
remove_var("https_proxy");
Expand All @@ -26,6 +32,9 @@ fn scrub_env() {
// Tests for correctly retrieving the proxy (host, port) tuple from $https_proxy
#[test]
fn read_basic_proxy_params() {
let _guard = SERIALISE_TESTS
.lock()
.expect("Unable to lock the test guard");
scrub_env();
set_var("https_proxy", "http://proxy.example.com:8080");
let u = Url::parse("https://www.example.org").ok().unwrap();
Expand All @@ -39,6 +48,9 @@ fn read_basic_proxy_params() {
#[test]
fn socks_proxy_request() {
static CALL_COUNT: AtomicUsize = AtomicUsize::new(0);
let _guard = SERIALISE_TESTS
.lock()
.expect("Unable to lock the test guard");

scrub_env();
set_var("all_proxy", "socks5://127.0.0.1:1080");
Expand Down

0 comments on commit ccb103b

Please sign in to comment.