@@ -4,15 +4,16 @@ use std::env::{remove_var, set_var};
4
4
use std:: error:: Error ;
5
5
use std:: net:: TcpListener ;
6
6
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
7
- use std:: sync:: Mutex ;
8
7
use std:: thread;
9
8
use std:: time:: Duration ;
10
9
11
10
use env_proxy:: for_url;
11
+ use once_cell:: sync:: Lazy ;
12
12
use reqwest:: { Client , Proxy } ;
13
+ use tokio:: sync:: Mutex ;
13
14
use url:: Url ;
14
15
15
- static SERIALISE_TESTS : Mutex < ( ) > = Mutex :: new ( ( ) ) ;
16
+ static SERIALISE_TESTS : Lazy < Mutex < ( ) > > = Lazy :: new ( || Mutex :: new ( ( ) ) ) ;
16
17
17
18
fn scrub_env ( ) {
18
19
remove_var ( "http_proxy" ) ;
@@ -29,9 +30,7 @@ fn scrub_env() {
29
30
// Tests for correctly retrieving the proxy (host, port) tuple from $https_proxy
30
31
#[ tokio:: test]
31
32
async 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 ;
35
34
scrub_env ( ) ;
36
35
set_var ( "https_proxy" , "http://proxy.example.com:8080" ) ;
37
36
let u = Url :: parse ( "https://www.example.org" ) . ok ( ) . unwrap ( ) ;
@@ -45,9 +44,7 @@ async fn read_basic_proxy_params() {
45
44
#[ tokio:: test]
46
45
async fn socks_proxy_request ( ) {
47
46
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 ;
51
48
52
49
scrub_env ( ) ;
53
50
set_var ( "all_proxy" , "socks5://127.0.0.1:1080" ) ;
0 commit comments