Skip to content

Commit

Permalink
some test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeen committed Dec 29, 2024
1 parent d361abf commit 91a3557
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
26 changes: 25 additions & 1 deletion nativelink-service/tests/store_overlap_rules_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -32,13 +32,37 @@ 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()),
&store_manager,
None,
)
.await
.is_ok());

assert!(make_and_add_store_to_manager(
"main_ac",
&StoreSpec::memory(MemorySpec::default()),
&store_manager,
None,
)
.await
.is_err());

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion nativelink-store/tests/redis_store_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
40 changes: 23 additions & 17 deletions nativelink-store/tests/ref_store_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,27 +28,32 @@ use pretty_assertions::assert_eq;

const VALID_HASH1: &str = "0123456789abcdef000000000000000000010000000000000123456789abcdef";

fn setup_stores() -> (Arc<StoreManager>, Store, Store) {
async fn setup_stores() -> (Arc<StoreManager>, 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)
}

#[nativelink_test]
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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -140,23 +146,23 @@ 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 {
name: "mem_store".to_string(),
},
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 {
name: "ref_store_inner".to_string(),
},
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!(
Expand Down

0 comments on commit 91a3557

Please sign in to comment.