Skip to content

Commit fbf9d1d

Browse files
author
Zoran Cvetkov
committed
cleanup
1 parent 226abe7 commit fbf9d1d

File tree

1 file changed

+45
-50
lines changed

1 file changed

+45
-50
lines changed

store/test-store/tests/graph/entity_cache.rs

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ async fn insert_test_data(store: Arc<DieselSubgraphStore>) -> DeploymentLocator
469469

470470
fn create_account_entity(id: &str, name: &str, email: &str, age: i32, vid: i64) -> EntityOperation {
471471
let test_entity =
472-
entity! { LOAD_RELATED_SUBGRAPH => id: id, name: name, email: email, age: age, vid: vid };
472+
entity! { LOAD_RELATED_SUBGRAPH => id: id, name: name, email: email, age: age };
473473

474474
EntityOperation::Set {
475475
key: ACCOUNT_TYPE.parse_key(id).unwrap(),
@@ -479,8 +479,7 @@ fn create_account_entity(id: &str, name: &str, email: &str, age: i32, vid: i64)
479479

480480
fn create_wallet_entity(id: &str, account_id: &Id, balance: i32, vid: i64) -> EntityV {
481481
let account_id = Value::from(account_id.clone());
482-
let e =
483-
entity! { LOAD_RELATED_SUBGRAPH => id: id, account: account_id, balance: balance, vid: vid};
482+
let e = entity! { LOAD_RELATED_SUBGRAPH => id: id, account: account_id, balance: balance};
484483
EntityV::new(e, vid)
485484
}
486485
fn create_wallet_operation(id: &str, account_id: &Id, balance: i32, vid: i64) -> EntityOperation {
@@ -716,53 +715,49 @@ fn check_for_delete_async_related() {
716715
});
717716
}
718717

719-
// #[test]
720-
// fn scoped_get() {
721-
// run_store_test(|mut cache, _store, _deployment, _writable| async move {
722-
// // Key for an existing entity that is in the store
723-
// let account1 = ACCOUNT_TYPE.parse_id("1").unwrap();
724-
// let key1 = WALLET_TYPE.parse_key("1").unwrap();
725-
// let wallet1 = create_wallet_entity("1", &account1, 67, 1);
726-
727-
// // Create a new entity that is not in the store
728-
// let account5 = ACCOUNT_TYPE.parse_id("5").unwrap();
729-
// let wallet5 = create_wallet_entity("5", &account5, 100, 5);
730-
// let key5 = WALLET_TYPE.parse_key("5").unwrap();
731-
// cache
732-
// .set(key5.clone(), EntityV::new(wallet5.clone(), 5))
733-
// .unwrap();
734-
735-
// // For the new entity, we can retrieve it with either scope
736-
// let act5 = cache.get(&key5, GetScope::InBlock).unwrap();
737-
// assert_eq!(Some(&wallet5), act5.as_ref().map(|e| e.as_ref()));
738-
// let act5 = cache.get(&key5, GetScope::Store).unwrap();
739-
// assert_eq!(Some(&wallet5), act5.as_ref().map(|e| e.as_ref()));
740-
741-
// // For an entity in the store, we can not get it `InBlock` but with
742-
// // `Store`
743-
// let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
744-
// assert_eq!(None, act1);
745-
// let act1 = cache.get(&key1, GetScope::Store).unwrap();
746-
// assert_eq!(
747-
// filter_vid(vec![wallet1.clone()]),
748-
// vec![act1.as_ref().map(|e| e.as_ref()).unwrap().clone()]
749-
// );
750-
// // Even after reading from the store, the entity is not visible with
751-
// // `InBlock`
752-
// let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
753-
// assert_eq!(None, act1);
754-
// // But if it gets updated, it becomes visible with either scope
755-
// let mut wallet1 = wallet1;
756-
// wallet1.set("balance", 70).unwrap();
757-
// cache
758-
// .set(key1.clone(), EntityV::new(wallet1.clone(), 1))
759-
// .unwrap();
760-
// let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
761-
// assert_eq!(Some(&wallet1), act1.as_ref().map(|e| e.as_ref()));
762-
// let act1 = cache.get(&key1, GetScope::Store).unwrap();
763-
// assert_eq!(Some(&wallet1), act1.as_ref().map(|e| e.as_ref()));
764-
// })
765-
// }
718+
#[test]
719+
fn scoped_get() {
720+
run_store_test(|mut cache, _store, _deployment, _writable| async move {
721+
// Key for an existing entity that is in the store
722+
let account1 = ACCOUNT_TYPE.parse_id("1").unwrap();
723+
let key1 = WALLET_TYPE.parse_key("1").unwrap();
724+
let wallet1 = create_wallet_entity("1", &account1, 67, 1);
725+
726+
// Create a new entity that is not in the store
727+
let account5 = ACCOUNT_TYPE.parse_id("5").unwrap();
728+
let wallet5 = create_wallet_entity("5", &account5, 100, 5);
729+
let key5 = WALLET_TYPE.parse_key("5").unwrap();
730+
cache.set(key5.clone(), wallet5.clone()).unwrap();
731+
732+
// For the new entity, we can retrieve it with either scope
733+
let act5 = cache.get(&key5, GetScope::InBlock).unwrap();
734+
assert_eq!(Some(&wallet5.e), act5.as_ref().map(|e| e.as_ref()));
735+
let act5 = cache.get(&key5, GetScope::Store).unwrap();
736+
assert_eq!(Some(&wallet5.e), act5.as_ref().map(|e| e.as_ref()));
737+
738+
// For an entity in the store, we can not get it `InBlock` but with
739+
// `Store`
740+
let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
741+
assert_eq!(None, act1);
742+
let act1 = cache.get(&key1, GetScope::Store).unwrap();
743+
assert_eq!(
744+
filter_vid(vec![wallet1.e.clone()]),
745+
vec![act1.as_ref().map(|e| e.as_ref()).unwrap().clone()]
746+
);
747+
// Even after reading from the store, the entity is not visible with
748+
// `InBlock`
749+
let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
750+
assert_eq!(None, act1);
751+
// But if it gets updated, it becomes visible with either scope
752+
let mut wallet1 = wallet1;
753+
wallet1.e.set("balance", 70).unwrap();
754+
cache.set(key1.clone(), wallet1.clone()).unwrap();
755+
let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
756+
assert_eq!(Some(&wallet1.e), act1.as_ref().map(|e| e.as_ref()));
757+
let act1 = cache.get(&key1, GetScope::Store).unwrap();
758+
assert_eq!(Some(&wallet1.e), act1.as_ref().map(|e| e.as_ref()));
759+
})
760+
}
766761

767762
/// Entities should never contain a `__typename` or `g$parent_id` field, if
768763
/// they do, that can cause PoI divergences, because entities will differ

0 commit comments

Comments
 (0)