Skip to content

Commit daeebf5

Browse files
committed
test suite
1 parent 1e29463 commit daeebf5

1 file changed

Lines changed: 180 additions & 61 deletions

File tree

crates/re_query_cache/tests/latest_at.rs

Lines changed: 180 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use itertools::Itertools as _;
66

77
use re_data_store::{DataStore, LatestAtQuery};
8-
use re_log_types::{build_frame_nr, DataRow, EntityPath, RowId};
8+
use re_log_types::{build_frame_nr, DataRow, EntityPath, RowId, TimePoint};
99
use re_query_cache::query_archetype_pov1_comp1;
1010
use re_types::{
1111
archetypes::Points2D,
@@ -159,79 +159,170 @@ fn splatted_query() {
159159
}
160160

161161
#[test]
162-
// TODO(cmc): implement invalidation + in-depth invalidation tests + in-depth OOO tests
163-
#[should_panic(expected = "assertion failed: `(left == right)`")]
164162
fn invalidation() {
165-
let mut store = DataStore::new(
166-
re_log_types::StoreId::random(re_log_types::StoreKind::Recording),
167-
InstanceKey::name(),
168-
Default::default(),
169-
);
170-
171163
let ent_path = "point";
172-
let timepoint = [build_frame_nr(123.into())];
173164

174-
// Create some positions with implicit instances
175-
let positions = vec![Position2D::new(1.0, 2.0), Position2D::new(3.0, 4.0)];
176-
let row = DataRow::from_cells1_sized(RowId::new(), ent_path, timepoint, 2, positions).unwrap();
177-
store.insert_row(&row).unwrap();
165+
let test_invalidation = |query: LatestAtQuery,
166+
present_data_timepoint: TimePoint,
167+
past_data_timepoint: TimePoint,
168+
future_data_timepoint: TimePoint| {
169+
let mut store = DataStore::new(
170+
re_log_types::StoreId::random(re_log_types::StoreKind::Recording),
171+
InstanceKey::name(),
172+
Default::default(),
173+
);
174+
175+
// Create some positions with implicit instances
176+
let positions = vec![Position2D::new(1.0, 2.0), Position2D::new(3.0, 4.0)];
177+
let row = DataRow::from_cells1_sized(
178+
RowId::new(),
179+
ent_path,
180+
present_data_timepoint.clone(),
181+
2,
182+
positions,
183+
)
184+
.unwrap();
185+
store.insert_row(&row).unwrap();
178186

179-
// Assign one of them a color with an explicit instance
180-
let color_instances = vec![InstanceKey(1)];
181-
let colors = vec![Color::from_rgb(255, 0, 0)];
182-
let row = DataRow::from_cells2_sized(
183-
RowId::new(),
184-
ent_path,
185-
timepoint,
186-
1,
187-
(color_instances, colors),
188-
)
189-
.unwrap();
190-
store.insert_row(&row).unwrap();
187+
// Assign one of them a color with an explicit instance
188+
let color_instances = vec![InstanceKey(1)];
189+
let colors = vec![Color::from_rgb(1, 2, 3)];
190+
let row = DataRow::from_cells2_sized(
191+
RowId::new(),
192+
ent_path,
193+
present_data_timepoint.clone(),
194+
1,
195+
(color_instances, colors),
196+
)
197+
.unwrap();
198+
store.insert_row(&row).unwrap();
191199

192-
let query = re_data_store::LatestAtQuery::new(timepoint[0].0, timepoint[0].1);
193-
query_and_compare(&store, &query, &ent_path.into());
200+
query_and_compare(&store, &query, &ent_path.into());
194201

195-
// Invalidate the PoV component
196-
let positions = vec![Position2D::new(10.0, 20.0), Position2D::new(30.0, 40.0)];
197-
let row = DataRow::from_cells1_sized(RowId::new(), ent_path, timepoint, 2, positions).unwrap();
198-
store.insert_row(&row).unwrap();
202+
// --- Modify present ---
199203

200-
let query = re_data_store::LatestAtQuery::new(timepoint[0].0, timepoint[0].1);
201-
query_and_compare(&store, &query, &ent_path.into());
204+
// Modify the PoV component
205+
let positions = vec![Position2D::new(10.0, 20.0), Position2D::new(30.0, 40.0)];
206+
let row = DataRow::from_cells1_sized(
207+
RowId::new(),
208+
ent_path,
209+
present_data_timepoint.clone(),
210+
2,
211+
positions,
212+
)
213+
.unwrap();
214+
store.insert_row(&row).unwrap();
202215

203-
// Invalidate the optional component
204-
let colors = vec![Color::from_rgb(255, 0, 0), Color::from_rgb(0, 255, 0)];
205-
let row = DataRow::from_cells1_sized(RowId::new(), ent_path, timepoint, 2, colors).unwrap();
206-
store.insert_row(&row).unwrap();
216+
query_and_compare(&store, &query, &ent_path.into());
207217

208-
let query = re_data_store::LatestAtQuery::new(timepoint[0].0, timepoint[0].1);
209-
query_and_compare(&store, &query, &ent_path.into());
218+
// Modify the optional component
219+
let colors = vec![Color::from_rgb(4, 5, 6), Color::from_rgb(7, 8, 9)];
220+
let row =
221+
DataRow::from_cells1_sized(RowId::new(), ent_path, present_data_timepoint, 2, colors)
222+
.unwrap();
223+
store.insert_row(&row).unwrap();
224+
225+
query_and_compare(&store, &query, &ent_path.into());
226+
227+
// --- Modify past ---
228+
229+
// Modify the PoV component
230+
let positions = vec![Position2D::new(100.0, 200.0), Position2D::new(300.0, 400.0)];
231+
let row = DataRow::from_cells1_sized(
232+
RowId::new(),
233+
ent_path,
234+
past_data_timepoint.clone(),
235+
2,
236+
positions,
237+
)
238+
.unwrap();
239+
store.insert_row(&row).unwrap();
240+
241+
query_and_compare(&store, &query, &ent_path.into());
242+
243+
// Modify the optional component
244+
let colors = vec![Color::from_rgb(10, 11, 12), Color::from_rgb(13, 14, 15)];
245+
let row =
246+
DataRow::from_cells1_sized(RowId::new(), ent_path, past_data_timepoint, 2, colors)
247+
.unwrap();
248+
store.insert_row(&row).unwrap();
249+
250+
query_and_compare(&store, &query, &ent_path.into());
251+
252+
// --- Modify future ---
253+
254+
// Modify the PoV component
255+
let positions = vec![
256+
Position2D::new(1000.0, 2000.0),
257+
Position2D::new(3000.0, 4000.0),
258+
];
259+
let row = DataRow::from_cells1_sized(
260+
RowId::new(),
261+
ent_path,
262+
future_data_timepoint.clone(),
263+
2,
264+
positions,
265+
)
266+
.unwrap();
267+
store.insert_row(&row).unwrap();
268+
269+
query_and_compare(&store, &query, &ent_path.into());
270+
271+
// Modify the optional component
272+
let colors = vec![Color::from_rgb(16, 17, 18)];
273+
let row =
274+
DataRow::from_cells1_sized(RowId::new(), ent_path, future_data_timepoint, 1, colors)
275+
.unwrap();
276+
store.insert_row(&row).unwrap();
277+
278+
query_and_compare(&store, &query, &ent_path.into());
279+
};
280+
281+
let timeless = TimePoint::timeless();
282+
let frame_122 = build_frame_nr(123.into());
283+
let frame_123 = build_frame_nr(123.into());
284+
let frame_124 = build_frame_nr(123.into());
285+
286+
test_invalidation(
287+
LatestAtQuery {
288+
timeline: frame_123.0,
289+
at: frame_123.1,
290+
},
291+
[frame_123].into(),
292+
[frame_122].into(),
293+
[frame_124].into(),
294+
);
295+
296+
test_invalidation(
297+
LatestAtQuery {
298+
timeline: frame_123.0,
299+
at: frame_123.1,
300+
},
301+
[frame_123].into(),
302+
timeless,
303+
[frame_124].into(),
304+
);
210305
}
211306

212307
// Test the following scenario:
213308
// ```py
214-
// rr.set_time(0)
215-
// rr.log("points", rr.Points3D([1, 2, 3]))
309+
// rr.log("points", rr.Points3D([1, 2, 3]), timeless=True)
216310
//
217311
// # Do first query here: LatestAt(+inf)
218312
// # Expected: points=[[1,2,3]] colors=[]
219313
//
220-
// rr.set_time(1)
314+
// rr.set_time(2)
221315
// rr.log_components("points", rr.components.Color(0xFF0000))
222316
//
223317
// # Do second query here: LatestAt(+inf)
224318
// # Expected: points=[[1,2,3]] colors=[0xFF0000]
225319
//
226-
// rr.set_time(2)
320+
// rr.set_time(3)
227321
// rr.log_components("points", rr.components.Color(0x0000FF))
228322
//
229323
// # Do third query here: LatestAt(+inf)
230324
// # Expected: points=[[1,2,3]] colors=[0x0000FF]
231325
// ```
232-
//
233-
// TODO(cmc): this needs proper invalidation to pass
234-
#[should_panic(expected = "assertion failed: `(left == right)`")]
235326
#[test]
236327
fn invalidation_of_future_optionals() {
237328
let mut store = DataStore::new(
@@ -242,14 +333,14 @@ fn invalidation_of_future_optionals() {
242333

243334
let ent_path = "points";
244335

245-
let frame1 = [build_frame_nr(1.into())];
336+
let timeless = TimePoint::timeless();
246337
let frame2 = [build_frame_nr(2.into())];
247338
let frame3 = [build_frame_nr(3.into())];
248339

249340
let query_time = [build_frame_nr(9999.into())];
250341

251342
let positions = vec![Position2D::new(1.0, 2.0), Position2D::new(3.0, 4.0)];
252-
let row = DataRow::from_cells1_sized(RowId::new(), ent_path, frame1, 2, positions).unwrap();
343+
let row = DataRow::from_cells1_sized(RowId::new(), ent_path, timeless, 2, positions).unwrap();
253344
store.insert_row(&row).unwrap();
254345

255346
let query = re_data_store::LatestAtQuery::new(query_time[0].0, query_time[0].1);
@@ -280,25 +371,44 @@ fn invalidation_of_future_optionals() {
280371

281372
fn query_and_compare(store: &DataStore, query: &LatestAtQuery, ent_path: &EntityPath) {
282373
for _ in 0..3 {
283-
let mut got_instance_keys = Vec::new();
284-
let mut got_positions = Vec::new();
285-
let mut got_colors = Vec::new();
374+
let mut uncached_data_time = None;
375+
let mut uncached_instance_keys = Vec::new();
376+
let mut uncached_positions = Vec::new();
377+
let mut uncached_colors = Vec::new();
378+
query_archetype_pov1_comp1::<Points2D, Position2D, Color, _>(
379+
false, // cached?
380+
store,
381+
&query.clone().into(),
382+
ent_path,
383+
|((data_time, _), instance_keys, positions, colors)| {
384+
uncached_data_time = data_time;
385+
uncached_instance_keys.extend(instance_keys.iter().copied());
386+
uncached_positions.extend(positions.iter().copied());
387+
uncached_colors.extend(colors.iter().copied());
388+
},
389+
)
390+
.unwrap();
286391

392+
let mut cached_data_time = None;
393+
let mut cached_instance_keys = Vec::new();
394+
let mut cached_positions = Vec::new();
395+
let mut cached_colors = Vec::new();
287396
query_archetype_pov1_comp1::<Points2D, Position2D, Color, _>(
288397
true, // cached?
289398
store,
290399
&query.clone().into(),
291400
ent_path,
292-
|(_, instance_keys, positions, colors)| {
293-
got_instance_keys.extend(instance_keys.iter().copied());
294-
got_positions.extend(positions.iter().copied());
295-
got_colors.extend(colors.iter().copied());
401+
|((data_time, _), instance_keys, positions, colors)| {
402+
cached_data_time = data_time;
403+
cached_instance_keys.extend(instance_keys.iter().copied());
404+
cached_positions.extend(positions.iter().copied());
405+
cached_colors.extend(colors.iter().copied());
296406
},
297407
)
298408
.unwrap();
299409

300-
let (_, expected) = re_query::query_archetype::<Points2D>(store, query, ent_path).unwrap();
301-
410+
let (expected_data_time, expected) =
411+
re_query::query_archetype::<Points2D>(store, query, ent_path).unwrap();
302412
let expected_instance_keys = expected.iter_instance_keys().collect_vec();
303413
let expected_positions = expected
304414
.iter_required_component::<Position2D>()
@@ -309,8 +419,17 @@ fn query_and_compare(store: &DataStore, query: &LatestAtQuery, ent_path: &Entity
309419
.unwrap()
310420
.collect_vec();
311421

312-
similar_asserts::assert_eq!(expected_instance_keys, got_instance_keys);
313-
similar_asserts::assert_eq!(expected_positions, got_positions);
314-
similar_asserts::assert_eq!(expected_colors, got_colors);
422+
// Keep this around for the next unlucky chap.
423+
// eprintln!("(expected={expected_data_time:?}, uncached={uncached_data_time:?}, cached={cached_data_time:?})");
424+
425+
similar_asserts::assert_eq!(expected_data_time, uncached_data_time);
426+
similar_asserts::assert_eq!(expected_instance_keys, uncached_instance_keys);
427+
similar_asserts::assert_eq!(expected_positions, uncached_positions);
428+
similar_asserts::assert_eq!(expected_colors, uncached_colors);
429+
430+
similar_asserts::assert_eq!(expected_data_time, cached_data_time);
431+
similar_asserts::assert_eq!(expected_instance_keys, cached_instance_keys);
432+
similar_asserts::assert_eq!(expected_positions, cached_positions);
433+
similar_asserts::assert_eq!(expected_colors, cached_colors);
315434
}
316435
}

0 commit comments

Comments
 (0)