MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / test_subscribe_progress

Function test_subscribe_progress

src/environmentd/tests/sql.rs:685–797  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

683#[mz_ore::test]
684#[allow(clippy::disallowed_methods)]
685fn test_subscribe_progress() {
686 let server = test_util::TestHarness::default().start_blocking();
687
688 for has_initial_data in [false, true] {
689 for has_index in [false, true] {
690 for has_snapshot in [false, true] {
691 let mut client_writes = server.connect(postgres::NoTls).unwrap();
692 let mut client_reads = server.connect(postgres::NoTls).unwrap();
693
694 info!(
695 msg = "Running test",
696 has_initial_data, has_index, has_snapshot
697 );
698
699 client_writes
700 .batch_execute("CREATE TABLE t1 (data text)")
701 .unwrap();
702 if has_index {
703 client_writes
704 .batch_execute("CREATE INDEX i1 on t1(data)")
705 .unwrap();
706 }
707 if has_initial_data {
708 client_writes
709 .batch_execute("INSERT INTO t1 VALUES ('snapdata')")
710 .unwrap();
711 }
712 client_reads
713 .batch_execute(&format!(
714 "COMMIT; BEGIN;
715 DECLARE c1 CURSOR FOR SUBSCRIBE t1 WITH (PROGRESS, SNAPSHOT = {})",
716 has_snapshot
717 ))
718 .unwrap();
719
720 // Asserts that the next data message is `data`. Ignores any progress
721 // messages that occur first.
722 //
723 // Returns the timestamp at which that data arrived.
724 fn await_data(
725 client: &mut postgres::Client,
726 last_seen_ts: &mut u64,
727 data: &str,
728 ) -> u64 {
729 // We have to try several times. It might be that the FETCH gets a
730 // progress statements rather than data. We retry until we get the batch
731 // that has the data.
732 debug!("awaiting data: {data}");
733 loop {
734 let rows = client.query("FETCH 1 c1", &[]).unwrap();
735 debug!(row = ?rows.first());
736 let data_row = match rows.first() {
737 Some(row) if row.try_get::<_, String>("data").is_ok() => row,
738 _ => continue, // retry
739 };
740 assert_eq!(data_row.get::<_, bool>("mz_progressed"), false);
741 assert_eq!(data_row.get::<_, i64>("mz_diff"), 1);
742 assert_eq!(data_row.get::<_, String>("data"), data);

Callers

nothing calls this directly

Calls 7

await_progressFunction · 0.85
await_dataFunction · 0.85
start_blockingMethod · 0.80
unwrapMethod · 0.80
batch_executeMethod · 0.80
connectMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected