From 91a355738febe50bbaaa13ec30900dda712b999d Mon Sep 17 00:00:00 2001 From: Mike Keen Date: Sun, 29 Dec 2024 15:11:54 -0500 Subject: [PATCH] some test fixes --- .../tests/store_overlap_rules_test.rs | 26 +++++++++++- nativelink-store/tests/redis_store_test.rs | 2 +- nativelink-store/tests/ref_store_test.rs | 40 +++++++++++-------- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/nativelink-service/tests/store_overlap_rules_test.rs b/nativelink-service/tests/store_overlap_rules_test.rs index 8506ad02b..c48b6bf73 100644 --- a/nativelink-service/tests/store_overlap_rules_test.rs +++ b/nativelink-service/tests/store_overlap_rules_test.rs @@ -21,7 +21,7 @@ use nativelink_store::default_store_factory::make_and_add_store_to_manager; use nativelink_store::store_manager::StoreManager; #[nativelink_test] -async fn same_datasource() -> Result<(), Error> { +async fn same_datasource_disallowed_simple() -> Result<(), Error> { let store_manager = Arc::new(StoreManager::new()); assert!(make_and_add_store_to_manager( "main_cas", @@ -32,6 +32,21 @@ async fn same_datasource() -> Result<(), Error> { .await .is_ok()); + assert!(make_and_add_store_to_manager( + "main_ac", + &StoreSpec::memory(MemorySpec::default()), + &store_manager, + None, + ) + .await + .is_err()); + + Ok(()) +} + +#[nativelink_test] +async fn same_datasource_disallowed_complex() -> Result<(), Error> { + let store_manager = Arc::new(StoreManager::new()); assert!(make_and_add_store_to_manager( "main_cas", &StoreSpec::memory(MemorySpec::default()), @@ -39,6 +54,15 @@ async fn same_datasource() -> Result<(), Error> { None, ) .await + .is_ok()); + + assert!(make_and_add_store_to_manager( + "main_ac", + &StoreSpec::memory(MemorySpec::default()), + &store_manager, + None, + ) + .await .is_err()); Ok(()) diff --git a/nativelink-store/tests/redis_store_test.rs b/nativelink-store/tests/redis_store_test.rs index 48f1cbdfa..2b2d71c85 100644 --- a/nativelink-store/tests/redis_store_test.rs +++ b/nativelink-store/tests/redis_store_test.rs @@ -883,7 +883,7 @@ async fn test_redis_fingerprint_metric() -> Result<(), Error> { )) }; - store_manager.add_store("redis_store", store); + store_manager.add_store("redis_store", store).unwrap(); }; let root_metrics = Arc::new(RwLock::new(RootMetricsTest { diff --git a/nativelink-store/tests/ref_store_test.rs b/nativelink-store/tests/ref_store_test.rs index 18b1463a0..a26752a0d 100644 --- a/nativelink-store/tests/ref_store_test.rs +++ b/nativelink-store/tests/ref_store_test.rs @@ -15,9 +15,10 @@ use std::ptr::from_ref; use std::sync::Arc; -use nativelink_config::stores::{MemorySpec, RefSpec}; +use nativelink_config::stores::{MemorySpec, RefSpec, StoreSpec}; use nativelink_error::Error; use nativelink_macro::nativelink_test; +use nativelink_store::default_store_factory::make_and_add_store_to_manager; use nativelink_store::memory_store::MemoryStore; use nativelink_store::ref_store::RefStore; use nativelink_store::store_manager::StoreManager; @@ -27,19 +28,24 @@ use pretty_assertions::assert_eq; const VALID_HASH1: &str = "0123456789abcdef000000000000000000010000000000000123456789abcdef"; -fn setup_stores() -> (Arc, Store, Store) { +async fn setup_stores() -> (Arc, Store, Store) { let store_manager = Arc::new(StoreManager::new()); - let memory_store = Store::new(MemoryStore::new(&MemorySpec::default())); - store_manager.add_store("foo", memory_store.clone()); + let memory_store_spec = StoreSpec::memory(MemorySpec::default()); + + make_and_add_store_to_manager("foo", &memory_store_spec, &store_manager, None) + .await + .unwrap(); + + let ref_store_spec = StoreSpec::ref_store(RefSpec { name: "foo".into() }); + + make_and_add_store_to_manager("bar", &ref_store_spec, &store_manager, None) + .await + .unwrap(); + + let memory_store = store_manager.get_store("foo").unwrap(); + let ref_store = store_manager.get_store("bar").unwrap(); - let ref_store = Store::new(RefStore::new( - &RefSpec { - name: "foo".to_string(), - }, - Arc::downgrade(&store_manager), - )); - store_manager.add_store("bar", ref_store.clone()); (store_manager, memory_store, ref_store) } @@ -47,7 +53,7 @@ fn setup_stores() -> (Arc, Store, Store) { async fn has_test() -> Result<(), Error> { const VALUE1: &str = "13"; - let (_store_manager, memory_store, ref_store) = setup_stores(); + let (_store_manager, memory_store, ref_store) = setup_stores().await; { // Insert data into memory store. @@ -77,7 +83,7 @@ async fn has_test() -> Result<(), Error> { async fn get_test() -> Result<(), Error> { const VALUE1: &str = "13"; - let (_store_manager, memory_store, ref_store) = setup_stores(); + let (_store_manager, memory_store, ref_store) = setup_stores().await; { // Insert data into memory store. @@ -108,7 +114,7 @@ async fn get_test() -> Result<(), Error> { async fn update_test() -> Result<(), Error> { const VALUE1: &str = "13"; - let (_store_manager, memory_store, ref_store) = setup_stores(); + let (_store_manager, memory_store, ref_store) = setup_stores().await; { // Insert data into ref_store. @@ -140,7 +146,7 @@ async fn inner_store_test() -> Result<(), Error> { let store_manager = Arc::new(StoreManager::new()); let memory_store = Store::new(MemoryStore::new(&MemorySpec::default())); - store_manager.add_store("mem_store", memory_store.clone()); + store_manager.add_store("mem_store", memory_store.clone())?; let ref_store_inner = Store::new(RefStore::new( &RefSpec { @@ -148,7 +154,7 @@ async fn inner_store_test() -> Result<(), Error> { }, Arc::downgrade(&store_manager), )); - store_manager.add_store("ref_store_inner", ref_store_inner.clone()); + store_manager.add_store("ref_store_inner", ref_store_inner.clone())?; let ref_store_outer = Store::new(RefStore::new( &RefSpec { @@ -156,7 +162,7 @@ async fn inner_store_test() -> Result<(), Error> { }, Arc::downgrade(&store_manager), )); - store_manager.add_store("ref_store_outer", ref_store_outer.clone()); + store_manager.add_store("ref_store_outer", ref_store_outer.clone())?; // Ensure the result of inner_store() points to exact same memory store. assert_eq!(