Skip to content

Commit 6f5ea3a

Browse files
committed
WIP LICENSE
1 parent 57eeb78 commit 6f5ea3a

File tree

6 files changed

+111
-320
lines changed

6 files changed

+111
-320
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE-3rdparty.yml

Lines changed: 6 additions & 237 deletions
Large diffs are not rendered by default.

remote-config/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ serde_json = { version = "1.0", features = ["raw_value"] }
2929

3030
[dev-dependencies]
3131
hyper = { version = "0.14", features = ["client", "server", "backports", "deprecated"], default-features = false }
32-
lazy_static = "1.4.0"
3332
futures = "0.3"
3433

3534
[lib]

remote-config/src/fetch/fetcher.rs

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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
)

remote-config/src/fetch/multitarget.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,8 @@ mod tests {
769769
let state = Arc::new(NotifyState::default());
770770

771771
server.files.lock().unwrap().insert(
772-
PATH_FIRST.clone(),
773-
(vec![DUMMY_TARGET.clone()], 1, "v1".to_string()),
772+
get_path_first().clone(),
773+
(vec![get_dummy_target().clone()], 1, "v1".to_string()),
774774
);
775775

776776
let fut = storage.await_fetches(1);
@@ -787,14 +787,14 @@ mod tests {
787787
id: 1,
788788
state: state.clone(),
789789
},
790-
&OTHER_TARGET,
790+
get_other_target(),
791791
);
792792
assert_eq!(
793793
*fetcher
794794
.services
795795
.lock()
796796
.unwrap()
797-
.get(&*OTHER_TARGET)
797+
.get(get_other_target())
798798
.unwrap()
799799
.fetcher
800800
.runtime_id
@@ -809,23 +809,23 @@ mod tests {
809809
id: 1,
810810
state: state.clone(),
811811
},
812-
&DUMMY_TARGET,
812+
get_dummy_target(),
813813
);
814814
fetcher.add_runtime(
815815
RT_ID_2.to_string(),
816816
Notifier {
817817
id: 2,
818818
state: state.clone(),
819819
},
820-
&DUMMY_TARGET,
820+
get_dummy_target(),
821821
);
822822

823823
assert_eq!(
824824
*fetcher
825825
.services
826826
.lock()
827827
.unwrap()
828-
.get(&*DUMMY_TARGET)
828+
.get(get_dummy_target())
829829
.unwrap()
830830
.fetcher
831831
.runtime_id
@@ -838,7 +838,7 @@ mod tests {
838838
.services
839839
.lock()
840840
.unwrap()
841-
.get(&*OTHER_TARGET)
841+
.get(get_other_target())
842842
.unwrap()
843843
.fetcher
844844
.runtime_id
@@ -856,7 +856,7 @@ mod tests {
856856
id: 3,
857857
state: state.clone(),
858858
},
859-
&OTHER_TARGET,
859+
get_other_target(),
860860
);
861861

862862
fut.await;
@@ -866,7 +866,7 @@ mod tests {
866866
.recent_fetches
867867
.lock()
868868
.unwrap()
869-
.get(&*DUMMY_TARGET)
869+
.get(get_dummy_target())
870870
.unwrap()
871871
.iter()
872872
.map(|p| p.store.data.clone())
@@ -875,8 +875,8 @@ mod tests {
875875

876876
let fut = storage.await_fetches(2);
877877
server.files.lock().unwrap().insert(
878-
PATH_FIRST.clone(),
879-
(vec![OTHER_TARGET.clone()], 1, "v1".to_string()),
878+
get_path_first().clone(),
879+
(vec![get_other_target().clone()], 1, "v1".to_string()),
880880
);
881881

882882
fut.await;
@@ -886,7 +886,7 @@ mod tests {
886886
.recent_fetches
887887
.lock()
888888
.unwrap()
889-
.get(&*OTHER_TARGET)
889+
.get(get_other_target())
890890
.unwrap()
891891
.iter()
892892
.map(|p| p.store.data.clone())
@@ -896,7 +896,7 @@ mod tests {
896896
.recent_fetches
897897
.lock()
898898
.unwrap()
899-
.get(&*OTHER_TARGET)
899+
.get(get_other_target())
900900
.unwrap()
901901
.len(),
902902
1
@@ -908,14 +908,14 @@ mod tests {
908908
);
909909
}
910910

911-
fetcher.delete_runtime(RT_ID_1, &OTHER_TARGET);
912-
fetcher.delete_runtime(RT_ID_1, &DUMMY_TARGET);
913-
fetcher.delete_runtime(RT_ID_2, &DUMMY_TARGET);
914-
fetcher.delete_runtime(RT_ID_3, &OTHER_TARGET);
911+
fetcher.delete_runtime(RT_ID_1, get_other_target());
912+
fetcher.delete_runtime(RT_ID_1, get_dummy_target());
913+
fetcher.delete_runtime(RT_ID_2, get_dummy_target());
914+
fetcher.delete_runtime(RT_ID_3, get_other_target());
915915

916916
fetcher.shutdown();
917-
storage.expect_expiration(&DUMMY_TARGET);
918-
storage.expect_expiration(&OTHER_TARGET);
917+
storage.expect_expiration(get_dummy_target());
918+
storage.expect_expiration(get_other_target());
919919

920920
on_dead.await
921921
}

0 commit comments

Comments
 (0)