@@ -529,27 +529,42 @@ pub mod tests {
529529 use crate :: RemoteConfigSource ;
530530 use http:: Response ;
531531 use hyper:: Body ;
532- use lazy_static :: lazy_static ;
532+ use std :: sync :: OnceLock ;
533533
534- lazy_static ! {
535- pub static ref PATH_FIRST : RemoteConfigPath = RemoteConfigPath {
534+ // TODO: Move to the more ergonomic LazyLock when MSRV is 1.80
535+ static PATH_FIRST : OnceLock < RemoteConfigPath > = OnceLock :: new ( ) ;
536+
537+ pub ( crate ) fn get_path_first ( ) -> & ' static RemoteConfigPath {
538+ PATH_FIRST . get_or_init ( || RemoteConfigPath {
536539 source : RemoteConfigSource :: Employee ,
537540 product : RemoteConfigProduct :: ApmTracing ,
538541 config_id : "1234" . to_string ( ) ,
539542 name : "config" . to_string ( ) ,
540- } ;
541- pub static ref PATH_SECOND : RemoteConfigPath = RemoteConfigPath {
543+ } )
544+ }
545+
546+ static PATH_SECOND : OnceLock < RemoteConfigPath > = OnceLock :: new ( ) ;
547+
548+ pub ( crate ) fn get_path_second ( ) -> & ' static RemoteConfigPath {
549+ PATH_SECOND . get_or_init ( || RemoteConfigPath {
542550 source : RemoteConfigSource :: Employee ,
543551 product : RemoteConfigProduct :: ApmTracing ,
544552 config_id : "9876" . to_string ( ) ,
545553 name : "config" . to_string ( ) ,
546- } ;
547- pub static ref DUMMY_TARGET : Arc <Target > = Arc :: new( Target {
548- service: "service" . to_string( ) ,
549- env: "env" . to_string( ) ,
550- app_version: "1.3.5" . to_string( ) ,
551- tags: vec![ ] ,
552- } ) ;
554+ } )
555+ }
556+
557+ static DUMMY_TARGET : OnceLock < Arc < Target > > = OnceLock :: new ( ) ;
558+
559+ pub ( crate ) fn get_dummy_target ( ) -> & ' static Arc < Target > {
560+ DUMMY_TARGET . get_or_init ( || {
561+ Arc :: new ( Target {
562+ service : "service" . to_string ( ) ,
563+ env : "env" . to_string ( ) ,
564+ app_version : "1.3.5" . to_string ( ) ,
565+ tags : vec ! [ ] ,
566+ } )
567+ } )
553568 }
554569
555570 static DUMMY_RUNTIME_ID : & str = "3b43524b-a70c-45dc-921d-34504e50c5eb" ;
@@ -635,7 +650,7 @@ pub mod tests {
635650 let fetched = fetcher
636651 . fetch_once (
637652 DUMMY_RUNTIME_ID ,
638- DUMMY_TARGET . clone ( ) ,
653+ get_dummy_target ( ) . clone ( ) ,
639654 "foo" ,
640655 & mut opaque_state,
641656 )
@@ -651,8 +666,8 @@ pub mod tests {
651666 async fn test_fetch_cache ( ) {
652667 let server = RemoteConfigServer :: spawn ( ) ;
653668 server. files . lock ( ) . unwrap ( ) . insert (
654- PATH_FIRST . clone ( ) ,
655- ( vec ! [ DUMMY_TARGET . clone( ) ] , 1 , "v1" . to_string ( ) ) ,
669+ get_path_first ( ) . clone ( ) ,
670+ ( vec ! [ get_dummy_target ( ) . clone( ) ] , 1 , "v1" . to_string ( ) ) ,
656671 ) ;
657672
658673 let storage = Arc :: new ( Storage :: default ( ) ) ;
@@ -679,7 +694,7 @@ pub mod tests {
679694 let fetched = fetcher
680695 . fetch_once (
681696 DUMMY_RUNTIME_ID ,
682- DUMMY_TARGET . clone ( ) ,
697+ get_dummy_target ( ) . clone ( ) ,
683698 "foo" ,
684699 & mut opaque_state,
685700 )
@@ -705,9 +720,9 @@ pub mod tests {
705720 assert ! ( state. backend_client_state. is_empty( ) ) ;
706721
707722 let tracer = client. client_tracer . as_ref ( ) . unwrap ( ) ;
708- assert_eq ! ( tracer. service, DUMMY_TARGET . service) ;
709- assert_eq ! ( tracer. env, DUMMY_TARGET . env) ;
710- assert_eq ! ( tracer. app_version, DUMMY_TARGET . app_version) ;
723+ assert_eq ! ( tracer. service, get_dummy_target ( ) . service) ;
724+ assert_eq ! ( tracer. env, get_dummy_target ( ) . env) ;
725+ assert_eq ! ( tracer. app_version, get_dummy_target ( ) . app_version) ;
711726 assert_eq ! ( tracer. runtime_id, DUMMY_RUNTIME_ID ) ;
712727 assert_eq ! ( tracer. language, "php" ) ;
713728 assert_eq ! ( tracer. tracer_version, "1.2.3" ) ;
@@ -721,7 +736,7 @@ pub mod tests {
721736
722737 assert ! ( Arc :: ptr_eq(
723738 & fetched[ 0 ] . data,
724- storage. files. lock( ) . unwrap( ) . get( & * PATH_FIRST ) . unwrap( )
739+ storage. files. lock( ) . unwrap( ) . get( get_path_first ( ) ) . unwrap( )
725740 ) ) ;
726741 assert_eq ! ( fetched[ 0 ] . data. lock( ) . unwrap( ) . contents, "v1" ) ;
727742 assert_eq ! ( fetched[ 0 ] . data. lock( ) . unwrap( ) . version, 1 ) ;
@@ -731,7 +746,7 @@ pub mod tests {
731746 let fetched = fetcher
732747 . fetch_once (
733748 DUMMY_RUNTIME_ID ,
734- DUMMY_TARGET . clone ( ) ,
749+ get_dummy_target ( ) . clone ( ) ,
735750 "foo" ,
736751 & mut opaque_state,
737752 )
@@ -756,25 +771,25 @@ pub mod tests {
756771 assert ! ( !state. backend_client_state. is_empty( ) ) ;
757772
758773 let cached = & req. cached_target_files [ 0 ] ;
759- assert_eq ! ( cached. path, PATH_FIRST . to_string( ) ) ;
774+ assert_eq ! ( cached. path, get_path_first ( ) . to_string( ) ) ;
760775 assert_eq ! ( cached. length, 2 ) ;
761776 assert_eq ! ( cached. hashes. len( ) , 1 ) ;
762777 }
763778
764779 server. files . lock ( ) . unwrap ( ) . insert (
765- PATH_FIRST . clone ( ) ,
766- ( vec ! [ DUMMY_TARGET . clone( ) ] , 2 , "v2" . to_string ( ) ) ,
780+ get_path_first ( ) . clone ( ) ,
781+ ( vec ! [ get_dummy_target ( ) . clone( ) ] , 2 , "v2" . to_string ( ) ) ,
767782 ) ;
768783 server. files . lock ( ) . unwrap ( ) . insert (
769- PATH_SECOND . clone ( ) ,
770- ( vec ! [ DUMMY_TARGET . clone( ) ] , 1 , "X" . to_string ( ) ) ,
784+ get_path_second ( ) . clone ( ) ,
785+ ( vec ! [ get_dummy_target ( ) . clone( ) ] , 1 , "X" . to_string ( ) ) ,
771786 ) ;
772787
773788 {
774789 let fetched = fetcher
775790 . fetch_once (
776791 DUMMY_RUNTIME_ID ,
777- DUMMY_TARGET . clone ( ) ,
792+ get_dummy_target ( ) . clone ( ) ,
778793 "foo" ,
779794 & mut opaque_state,
780795 )
@@ -792,14 +807,19 @@ pub mod tests {
792807
793808 assert ! ( Arc :: ptr_eq(
794809 & fetched[ first] . data,
795- storage. files. lock( ) . unwrap( ) . get( & * PATH_FIRST ) . unwrap( )
810+ storage. files. lock( ) . unwrap( ) . get( get_path_first ( ) ) . unwrap( )
796811 ) ) ;
797812 assert_eq ! ( fetched[ first] . data. lock( ) . unwrap( ) . contents, "v2" ) ;
798813 assert_eq ! ( fetched[ first] . data. lock( ) . unwrap( ) . version, 2 ) ;
799814
800815 assert ! ( Arc :: ptr_eq(
801816 & fetched[ second] . data,
802- storage. files. lock( ) . unwrap( ) . get( & * PATH_SECOND ) . unwrap( )
817+ storage
818+ . files
819+ . lock( )
820+ . unwrap( )
821+ . get( get_path_second( ) )
822+ . unwrap( )
803823 ) ) ;
804824 assert_eq ! ( fetched[ second] . data. lock( ) . unwrap( ) . contents, "X" ) ;
805825 assert_eq ! ( fetched[ second] . data. lock( ) . unwrap( ) . version, 1 ) ;
@@ -809,7 +829,7 @@ pub mod tests {
809829 let fetched = fetcher
810830 . fetch_once (
811831 DUMMY_RUNTIME_ID ,
812- DUMMY_TARGET . clone ( ) ,
832+ get_dummy_target ( ) . clone ( ) ,
813833 "foo" ,
814834 & mut opaque_state,
815835 )
@@ -818,13 +838,13 @@ pub mod tests {
818838 assert ! ( fetched. is_none( ) ) ; // no change
819839 }
820840
821- server. files . lock ( ) . unwrap ( ) . remove ( & * PATH_FIRST ) ;
841+ server. files . lock ( ) . unwrap ( ) . remove ( get_path_first ( ) ) ;
822842
823843 {
824844 let fetched = fetcher
825845 . fetch_once (
826846 DUMMY_RUNTIME_ID ,
827- DUMMY_TARGET . clone ( ) ,
847+ get_dummy_target ( ) . clone ( ) ,
828848 "foo" ,
829849 & mut opaque_state,
830850 )
0 commit comments