@@ -36,7 +36,7 @@ use crate::server::{state::HttpMockStateManager, HttpMockServerBuilder};
36
36
37
37
use crate :: Mock ;
38
38
use async_object_pool:: Pool ;
39
- use lazy_static :: lazy_static ;
39
+ use once_cell :: sync :: Lazy ;
40
40
use std:: {
41
41
cell:: Cell ,
42
42
future:: pending,
@@ -1364,31 +1364,33 @@ const LOCAL_SERVER_ADAPTER_GENERATOR: fn() -> Arc<dyn MockServerAdapter + Send +
1364
1364
Arc :: new ( LocalMockServerAdapter :: new ( addr, state_manager) )
1365
1365
} ;
1366
1366
1367
- lazy_static ! {
1368
- static ref LOCAL_SERVER_POOL_REF : Arc < Pool < Arc <dyn MockServerAdapter + Send + Sync >>> = {
1367
+ static LOCAL_SERVER_POOL_REF : Lazy < Arc < Pool < Arc < dyn MockServerAdapter + Send + Sync > > > > =
1368
+ Lazy :: new ( || {
1369
1369
let max_servers = read_env ( "HTTPMOCK_MAX_SERVERS" , "25" )
1370
1370
. parse :: < usize > ( )
1371
1371
. expect ( "Cannot parse environment variable HTTPMOCK_MAX_SERVERS as an integer" ) ;
1372
1372
Arc :: new ( Pool :: new ( max_servers) )
1373
- } ;
1374
- static ref REMOTE_SERVER_POOL_REF : Arc < Pool < Arc <dyn MockServerAdapter + Send + Sync >>> =
1375
- Arc :: new ( Pool :: new ( 1 ) ) ;
1376
- }
1373
+ } ) ;
1374
+
1375
+ static REMOTE_SERVER_POOL_REF : Lazy < Arc < Pool < Arc < dyn MockServerAdapter + Send + Sync > > > > =
1376
+ Lazy :: new ( || Arc :: new ( Pool :: new ( 1 ) ) ) ;
1377
1377
1378
1378
#[ cfg( feature = "remote" ) ]
1379
- lazy_static ! {
1380
- // TODO: REFACTOR to use a runtime agnostic HTTP client for remote access.
1381
- // This solution does not require OpenSSL and less dependencies compared to
1382
- // other HTTP clients (tested: isahc, surf). Curl seems to use OpenSSL by default,
1383
- // so this is not an option. Optimally, the HTTP client uses rustls to avoid the
1384
- // dependency on OpenSSL installed on the OS.
1385
- static ref REMOTE_SERVER_CLIENT : Arc <HttpMockHttpClient > = {
1386
- let max_workers = read_env( "HTTPMOCK_HTTP_CLIENT_WORKER_THREADS" , "1" )
1387
- . parse:: <usize >( )
1388
- . expect( "Cannot parse environment variable HTTPMOCK_HTTP_CLIENT_WORKER_THREADS as an integer" ) ;
1389
- let max_blocking_threads = read_env( "HTTPMOCK_HTTP_CLIENT_MAX_BLOCKING_THREADS" , "10" )
1390
- . parse:: <usize >( )
1391
- . expect( "Cannot parse environment variable HTTPMOCK_HTTP_CLIENT_MAX_BLOCKING_THREADS to an integer" ) ;
1392
- Arc :: new( HttpMockHttpClient :: new( Some ( Arc :: new( runtime:: new( max_workers, max_blocking_threads) . unwrap( ) ) ) ) )
1393
- } ;
1394
- }
1379
+ // TODO: REFACTOR to use a runtime agnostic HTTP client for remote access.
1380
+ // This solution does not require OpenSSL and less dependencies compared to
1381
+ // other HTTP clients (tested: isahc, surf). Curl seems to use OpenSSL by default,
1382
+ // so this is not an option. Optimally, the HTTP client uses rustls to avoid the
1383
+ // dependency on OpenSSL installed on the OS.
1384
+ static REMOTE_SERVER_CLIENT : Lazy < Arc < HttpMockHttpClient > > = Lazy :: new ( || {
1385
+ let max_workers = read_env ( "HTTPMOCK_HTTP_CLIENT_WORKER_THREADS" , "1" )
1386
+ . parse :: < usize > ( )
1387
+ . expect (
1388
+ "Cannot parse environment variable HTTPMOCK_HTTP_CLIENT_WORKER_THREADS as an integer" ,
1389
+ ) ;
1390
+ let max_blocking_threads = read_env ( "HTTPMOCK_HTTP_CLIENT_MAX_BLOCKING_THREADS" , "10" )
1391
+ . parse :: < usize > ( )
1392
+ . expect ( "Cannot parse environment variable HTTPMOCK_HTTP_CLIENT_MAX_BLOCKING_THREADS to an integer" ) ;
1393
+ Arc :: new ( HttpMockHttpClient :: new ( Some ( Arc :: new (
1394
+ runtime:: new ( max_workers, max_blocking_threads) . unwrap ( ) ,
1395
+ ) ) ) )
1396
+ } ) ;
0 commit comments