Skip to content

Commit ecc33c4

Browse files
author
Zoran Cvetkov
committed
fix relational tests
1 parent a83233b commit ecc33c4

File tree

4 files changed

+69
-34
lines changed

4 files changed

+69
-34
lines changed

store/test-store/src/store.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ lazy_static! {
105105
};
106106
}
107107

108+
pub fn filter_vid(arr: Vec<Entity>) -> Vec<Entity> {
109+
arr.into_iter()
110+
.map(|mut e| {
111+
e.remove("vid");
112+
e.remove_null_fields();
113+
e
114+
})
115+
.collect()
116+
}
117+
108118
/// Run the `test` after performing `setup`. The result of `setup` is passed
109119
/// into `test`. All tests using `run_test_sequentially` are run in sequence,
110120
/// never in parallel. The `test` is passed a `Store`, but it is permissible

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use std::sync::Arc;
2424
use web3::types::H256;
2525

2626
use graph_store_postgres::SubgraphStore as DieselSubgraphStore;
27+
use test_store::store::filter_vid;
2728
use test_store::*;
2829

2930
lazy_static! {
@@ -190,16 +191,6 @@ fn sort_by_entity_key(mut mods: Vec<EntityModification>) -> Vec<EntityModificati
190191
mods
191192
}
192193

193-
fn filter_vid(arr: Vec<Entity>) -> Vec<Entity> {
194-
arr.into_iter()
195-
.map(|mut e| {
196-
e.remove("vid");
197-
e.remove_null_fields();
198-
e
199-
})
200-
.collect()
201-
}
202-
203194
#[tokio::test]
204195
async fn empty_cache_modifications() {
205196
let store = Arc::new(MockStore::new(BTreeMap::new()));

store/test-store/tests/postgres/relational.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,13 @@ lazy_static! {
205205
bigInt: big_int.clone(),
206206
bigIntArray: vec![big_int.clone(), (big_int + 1.into())],
207207
color: "yellow",
208+
vid: 0i64,
208209
}
209210
};
210211
static ref EMPTY_NULLABLESTRINGS_ENTITY: Entity = {
211212
entity! { THINGS_SCHEMA =>
212213
id: "one",
214+
vid: 0i64,
213215
}
214216
};
215217
static ref SCALAR_TYPE: EntityType = THINGS_SCHEMA.entity_type("Scalar").unwrap();
@@ -463,17 +465,19 @@ fn insert_pet(
463465
id: &str,
464466
name: &str,
465467
block: BlockNumber,
468+
vid: i64,
466469
) {
467470
let pet = entity! { layout.input_schema =>
468471
id: id,
469-
name: name
472+
name: name,
473+
vid: vid,
470474
};
471475
insert_entity_at(conn, layout, entity_type, vec![pet], block);
472476
}
473477

474478
fn insert_pets(conn: &mut PgConnection, layout: &Layout) {
475-
insert_pet(conn, layout, &*DOG_TYPE, "pluto", "Pluto", 0);
476-
insert_pet(conn, layout, &*CAT_TYPE, "garfield", "Garfield", 0);
479+
insert_pet(conn, layout, &*DOG_TYPE, "pluto", "Pluto", 0, 0);
480+
insert_pet(conn, layout, &*CAT_TYPE, "garfield", "Garfield", 0, 1);
477481
}
478482

479483
fn create_schema(conn: &mut PgConnection) -> Layout {
@@ -493,6 +497,7 @@ fn create_schema(conn: &mut PgConnection) -> Layout {
493497
fn scrub(entity: &Entity) -> Entity {
494498
let mut scrubbed = entity.clone();
495499
scrubbed.remove_null_fields();
500+
scrubbed.remove("vid");
496501
scrubbed
497502
}
498503

@@ -606,6 +611,7 @@ fn update() {
606611
entity.set("string", "updated").unwrap();
607612
entity.remove("strings");
608613
entity.set("bool", Value::Null).unwrap();
614+
entity.set("vid", 1i64).unwrap();
609615
let key = SCALAR_TYPE.key(entity.id());
610616

611617
let entity_type = layout.input_schema.entity_type("Scalar").unwrap();
@@ -633,8 +639,10 @@ fn update_many() {
633639
let mut one = SCALAR_ENTITY.clone();
634640
let mut two = SCALAR_ENTITY.clone();
635641
two.set("id", "two").unwrap();
642+
two.set("vid", 1i64).unwrap();
636643
let mut three = SCALAR_ENTITY.clone();
637644
three.set("id", "three").unwrap();
645+
three.set("vid", 2i64).unwrap();
638646
insert_entity(
639647
conn,
640648
layout,
@@ -656,6 +664,10 @@ fn update_many() {
656664
three.remove("strings");
657665
three.set("color", "red").unwrap();
658666

667+
one.set("vid", 3i64).unwrap();
668+
two.set("vid", 4i64).unwrap();
669+
three.set("vid", 5i64).unwrap();
670+
659671
// generate keys
660672
let entity_type = layout.input_schema.entity_type("Scalar").unwrap();
661673
let keys: Vec<EntityKey> = ["one", "two", "three"]
@@ -722,10 +734,13 @@ fn serialize_bigdecimal() {
722734

723735
// Update with overwrite
724736
let mut entity = SCALAR_ENTITY.clone();
737+
let mut vid = 1i64;
725738

726739
for d in &["50", "50.00", "5000", "0.5000", "0.050", "0.5", "0.05"] {
727740
let d = BigDecimal::from_str(d).unwrap();
728741
entity.set("bigDecimal", d).unwrap();
742+
entity.set("vid", vid).unwrap();
743+
vid += 1;
729744

730745
let key = SCALAR_TYPE.key(entity.id());
731746
let entity_type = layout.input_schema.entity_type("Scalar").unwrap();
@@ -743,6 +758,7 @@ fn serialize_bigdecimal() {
743758
)
744759
.expect("Failed to read Scalar[one]")
745760
.unwrap();
761+
entity.remove("vid");
746762
assert_entity_eq!(entity, actual);
747763
}
748764
});
@@ -770,6 +786,7 @@ fn delete() {
770786
insert_entity(conn, layout, &*SCALAR_TYPE, vec![SCALAR_ENTITY.clone()]);
771787
let mut two = SCALAR_ENTITY.clone();
772788
two.set("id", "two").unwrap();
789+
two.set("vid", 1i64).unwrap();
773790
insert_entity(conn, layout, &*SCALAR_TYPE, vec![two]);
774791

775792
// Delete where nothing is getting deleted
@@ -804,8 +821,10 @@ fn insert_many_and_delete_many() {
804821
let one = SCALAR_ENTITY.clone();
805822
let mut two = SCALAR_ENTITY.clone();
806823
two.set("id", "two").unwrap();
824+
two.set("vid", 1i64).unwrap();
807825
let mut three = SCALAR_ENTITY.clone();
808826
three.set("id", "three").unwrap();
827+
three.set("vid", 2i64).unwrap();
809828
insert_entity(conn, layout, &*SCALAR_TYPE, vec![one, two, three]);
810829

811830
// confidence test: there should be 3 scalar entities in store right now
@@ -886,6 +905,7 @@ fn conflicting_entity() {
886905
cat: &str,
887906
dog: &str,
888907
ferret: &str,
908+
vid: i64,
889909
) {
890910
let conflicting =
891911
|conn: &mut PgConnection, entity_type: &EntityType, types: Vec<&EntityType>| {
@@ -912,7 +932,7 @@ fn conflicting_entity() {
912932
let dog_type = layout.input_schema.entity_type(dog).unwrap();
913933
let ferret_type = layout.input_schema.entity_type(ferret).unwrap();
914934

915-
let fred = entity! { layout.input_schema => id: id.clone(), name: id.clone() };
935+
let fred = entity! { layout.input_schema => id: id.clone(), name: id.clone(), vid: vid };
916936
insert_entity(conn, layout, &cat_type, vec![fred]);
917937

918938
// If we wanted to create Fred the dog, which is forbidden, we'd run this:
@@ -926,10 +946,10 @@ fn conflicting_entity() {
926946

927947
run_test(|mut conn, layout| {
928948
let id = Value::String("fred".to_string());
929-
check(&mut conn, layout, id, "Cat", "Dog", "Ferret");
949+
check(&mut conn, layout, id, "Cat", "Dog", "Ferret", 0);
930950

931951
let id = Value::Bytes(scalar::Bytes::from_str("0xf1ed").unwrap());
932-
check(&mut conn, layout, id, "ByteCat", "ByteDog", "ByteFerret");
952+
check(&mut conn, layout, id, "ByteCat", "ByteDog", "ByteFerret", 1);
933953
})
934954
}
935955

@@ -941,7 +961,8 @@ fn revert_block() {
941961
let set_fred = |conn: &mut PgConnection, name, block| {
942962
let fred = entity! { layout.input_schema =>
943963
id: id,
944-
name: name
964+
name: name,
965+
vid: block as i64,
945966
};
946967
if block == 0 {
947968
insert_entity_at(conn, layout, &*CAT_TYPE, vec![fred], block);
@@ -981,6 +1002,7 @@ fn revert_block() {
9811002
let marty = entity! { layout.input_schema =>
9821003
id: id,
9831004
order: block,
1005+
vid: (block + 10) as i64
9841006
};
9851007
insert_entity_at(conn, layout, &*MINK_TYPE, vec![marty], block);
9861008
}
@@ -1715,10 +1737,10 @@ struct FilterChecker<'a> {
17151737
impl<'a> FilterChecker<'a> {
17161738
fn new(conn: &'a mut PgConnection, layout: &'a Layout) -> Self {
17171739
let (a1, a2, a2b, a3) = ferrets();
1718-
insert_pet(conn, layout, &*FERRET_TYPE, "a1", &a1, 0);
1719-
insert_pet(conn, layout, &*FERRET_TYPE, "a2", &a2, 0);
1720-
insert_pet(conn, layout, &*FERRET_TYPE, "a2b", &a2b, 0);
1721-
insert_pet(conn, layout, &*FERRET_TYPE, "a3", &a3, 0);
1740+
insert_pet(conn, layout, &*FERRET_TYPE, "a1", &a1, 0, 0);
1741+
insert_pet(conn, layout, &*FERRET_TYPE, "a2", &a2, 0, 1);
1742+
insert_pet(conn, layout, &*FERRET_TYPE, "a2b", &a2b, 0, 2);
1743+
insert_pet(conn, layout, &*FERRET_TYPE, "a3", &a3, 0, 3);
17221744

17231745
Self { conn, layout }
17241746
}
@@ -1862,7 +1884,8 @@ fn check_filters() {
18621884
&*FERRET_TYPE,
18631885
vec![entity! { layout.input_schema =>
18641886
id: "a1",
1865-
name: "Test"
1887+
name: "Test",
1888+
vid: 5i64
18661889
}],
18671890
1,
18681891
);

store/test-store/tests/postgres/relational_bytes.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ lazy_static! {
5757
static ref BEEF_ENTITY: Entity = entity! { THINGS_SCHEMA =>
5858
id: scalar::Bytes::from_str("deadbeef").unwrap(),
5959
name: "Beef",
60+
vid: 0i64
6061
};
6162
static ref NAMESPACE: Namespace = Namespace::new("sgd0815".to_string()).unwrap();
6263
static ref THING_TYPE: EntityType = THINGS_SCHEMA.entity_type("Thing").unwrap();
@@ -83,8 +84,9 @@ pub fn row_group_update(
8384
) -> RowGroup {
8485
let mut group = RowGroup::new(entity_type.clone(), false);
8586
for (key, data) in data {
87+
let vid = data.vid();
8688
group
87-
.push(EntityModification::overwrite(key, data, block, 0), block)
89+
.push(EntityModification::overwrite(key, data, block, vid), block)
8890
.unwrap();
8991
}
9092
group
@@ -129,14 +131,15 @@ fn insert_entity(conn: &mut PgConnection, layout: &Layout, entity_type: &str, en
129131
layout.insert(conn, &group, &MOCK_STOPWATCH).expect(&errmsg);
130132
}
131133

132-
fn insert_thing(conn: &mut PgConnection, layout: &Layout, id: &str, name: &str) {
134+
fn insert_thing(conn: &mut PgConnection, layout: &Layout, id: &str, name: &str, vid: i64) {
133135
insert_entity(
134136
conn,
135137
layout,
136138
"Thing",
137139
entity! { layout.input_schema =>
138140
id: id,
139-
name: name
141+
name: name,
142+
vid: vid,
140143
},
141144
);
142145
}
@@ -159,6 +162,7 @@ fn create_schema(conn: &mut PgConnection) -> Layout {
159162
fn scrub(entity: &Entity) -> Entity {
160163
let mut scrubbed = entity.clone();
161164
scrubbed.remove_null_fields();
165+
scrubbed.remove("vid");
162166
scrubbed
163167
}
164168

@@ -266,7 +270,7 @@ fn find() {
266270

267271
const ID: &str = "deadbeef";
268272
const NAME: &str = "Beef";
269-
insert_thing(&mut conn, layout, ID, NAME);
273+
insert_thing(&mut conn, layout, ID, NAME, 0);
270274

271275
// Happy path: find existing entity
272276
let entity = find_entity(conn, layout, ID).unwrap();
@@ -286,8 +290,8 @@ fn find_many() {
286290
const NAME: &str = "Beef";
287291
const ID2: &str = "0xdeadbeef02";
288292
const NAME2: &str = "Moo";
289-
insert_thing(&mut conn, layout, ID, NAME);
290-
insert_thing(&mut conn, layout, ID2, NAME2);
293+
insert_thing(&mut conn, layout, ID, NAME, 0);
294+
insert_thing(&mut conn, layout, ID2, NAME2, 1);
291295

292296
let mut id_map = BTreeMap::default();
293297
let ids = IdList::try_from_iter(
@@ -319,6 +323,7 @@ fn update() {
319323
// Update the entity
320324
let mut entity = BEEF_ENTITY.clone();
321325
entity.set("name", "Moo").unwrap();
326+
entity.set("vid", 1i64).unwrap();
322327
let key = THING_TYPE.key(entity.id());
323328

324329
let entity_id = entity.id();
@@ -334,7 +339,7 @@ fn update() {
334339
.expect("Failed to read Thing[deadbeef]")
335340
.unwrap();
336341

337-
assert_entity_eq!(entity, actual);
342+
assert_entity_eq!(scrub(&entity), actual);
338343
});
339344
}
340345

@@ -346,6 +351,7 @@ fn delete() {
346351
insert_entity(&mut conn, layout, "Thing", BEEF_ENTITY.clone());
347352
let mut two = BEEF_ENTITY.clone();
348353
two.set("id", TWO_ID).unwrap();
354+
two.set("vid", 1i64).unwrap();
349355
insert_entity(&mut conn, layout, "Thing", two);
350356

351357
// Delete where nothing is getting deleted
@@ -393,29 +399,34 @@ fn make_thing_tree(conn: &mut PgConnection, layout: &Layout) -> (Entity, Entity,
393399
let root = entity! { layout.input_schema =>
394400
id: ROOT,
395401
name: "root",
396-
children: vec!["babe01", "babe02"]
402+
children: vec!["babe01", "babe02"],
403+
vid: 0i64,
397404
};
398405
let child1 = entity! { layout.input_schema =>
399406
id: CHILD1,
400407
name: "child1",
401408
parent: "dead00",
402-
children: vec![GRANDCHILD1]
409+
children: vec![GRANDCHILD1],
410+
vid: 1i64,
403411
};
404412
let child2 = entity! { layout.input_schema =>
405413
id: CHILD2,
406414
name: "child2",
407415
parent: "dead00",
408-
children: vec![GRANDCHILD1]
416+
children: vec![GRANDCHILD1],
417+
vid: 2i64,
409418
};
410419
let grand_child1 = entity! { layout.input_schema =>
411420
id: GRANDCHILD1,
412421
name: "grandchild1",
413-
parent: CHILD1
422+
parent: CHILD1,
423+
vid: 3i64,
414424
};
415425
let grand_child2 = entity! { layout.input_schema =>
416426
id: GRANDCHILD2,
417427
name: "grandchild2",
418-
parent: CHILD2
428+
parent: CHILD2,
429+
vid: 4i64,
419430
};
420431

421432
insert_entity(conn, layout, "Thing", root.clone());

0 commit comments

Comments
 (0)