@@ -4,15 +4,16 @@ use std::env::{remove_var, set_var};
44use std:: error:: Error ;
55use std:: net:: TcpListener ;
66use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
7- use std:: sync:: Mutex ;
87use std:: thread;
98use std:: time:: Duration ;
109
1110use env_proxy:: for_url;
11+ use once_cell:: sync:: Lazy ;
1212use reqwest:: { Client , Proxy } ;
13+ use tokio:: sync:: Mutex ;
1314use url:: Url ;
1415
15- static SERIALISE_TESTS : Mutex < ( ) > = Mutex :: new ( ( ) ) ;
16+ static SERIALISE_TESTS : Lazy < Mutex < ( ) > > = Lazy :: new ( || Mutex :: new ( ( ) ) ) ;
1617
1718fn scrub_env ( ) {
1819 remove_var ( "http_proxy" ) ;
@@ -29,9 +30,7 @@ fn scrub_env() {
2930// Tests for correctly retrieving the proxy (host, port) tuple from $https_proxy
3031#[ tokio:: test]
3132async fn read_basic_proxy_params ( ) {
32- let _guard = SERIALISE_TESTS
33- . lock ( )
34- . expect ( "Unable to lock the test guard" ) ;
33+ let _guard = SERIALISE_TESTS . lock ( ) . await ;
3534 scrub_env ( ) ;
3635 set_var ( "https_proxy" , "http://proxy.example.com:8080" ) ;
3736 let u = Url :: parse ( "https://www.example.org" ) . ok ( ) . unwrap ( ) ;
@@ -45,9 +44,7 @@ async fn read_basic_proxy_params() {
4544#[ tokio:: test]
4645async fn socks_proxy_request ( ) {
4746 static CALL_COUNT : AtomicUsize = AtomicUsize :: new ( 0 ) ;
48- let _guard = SERIALISE_TESTS
49- . lock ( )
50- . expect ( "Unable to lock the test guard" ) ;
47+ let _guard = SERIALISE_TESTS . lock ( ) . await ;
5148
5249 scrub_env ( ) ;
5350 set_var ( "all_proxy" , "socks5://127.0.0.1:1080" ) ;
0 commit comments