MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / test_views

Function test_views

crates/engine/src/relational_db.rs:2625–2703  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2623
2624 #[test]
2625 fn test_views() -> ResultTest<()> {
2626 let stdb = TestDB::durable()?;
2627
2628 let (view_id, table_id, _, _) = setup_view(&stdb)?;
2629
2630 let sender1 = Identity::ONE;
2631
2632 // Sender 1 insert
2633 insert_view_row(&stdb, view_id, table_id, sender1, 42)?;
2634
2635 assert_eq!(
2636 project_views(&stdb, table_id, sender1)[0],
2637 product![42u8],
2638 "View row not inserted correctly"
2639 );
2640
2641 // Sender 2 insert
2642 let sender2 = Identity::ZERO;
2643 let before_sender2 = Instant::now();
2644 insert_view_row(&stdb, view_id, table_id, sender2, 84)?;
2645
2646 assert_eq!(
2647 project_views(&stdb, table_id, sender2)[0],
2648 product![84u8],
2649 "Sender 2 view row not inserted correctly"
2650 );
2651
2652 // Restart database (view rows should NOT persist)
2653 let stdb = stdb.reopen()?;
2654
2655 assert!(
2656 project_views(&stdb, table_id, sender1).is_empty(),
2657 "Sender 1 rows should NOT persist after reopen"
2658 );
2659 assert!(
2660 project_views(&stdb, table_id, sender2).is_empty(),
2661 "Sender 2 rows should NOT persist after reopen"
2662 );
2663
2664 let tx = begin_mut_tx(&stdb);
2665 let st = tx.lookup_st_view_subs(view_id)?;
2666 assert!(st.is_empty(), "st_view_subs should also be cleared after restart");
2667 stdb.commit_tx(tx)?;
2668
2669 // Reinsert after restart
2670 insert_view_row(&stdb, view_id, table_id, sender2, 91)?;
2671 assert_eq!(
2672 project_views(&stdb, table_id, sender2)[0],
2673 product![91u8],
2674 "Post-restart inserted rows must appear"
2675 );
2676
2677 // Clean expired rows
2678 let mut tx = begin_mut_tx(&stdb);
2679 tx.clear_expired_views(
2680 Instant::now().saturating_duration_since(before_sender2),
2681 VIEW_CLEANUP_BUDGET,
2682 )?;

Callers

nothing calls this directly

Calls 8

setup_viewFunction · 0.85
insert_view_rowFunction · 0.85
reopenMethod · 0.80
lookup_st_view_subsMethod · 0.80
commit_txMethod · 0.80
clear_expired_viewsMethod · 0.80
begin_mut_txFunction · 0.70
OkFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…