Skip to content

Commit e1fdf26

Browse files
committed
readyset-psql: Make checking last statement more debuggable
Not that I love using macros everywhere, but this makes line numbers useful. Change-Id: I1ca080b58821fb44472bca07cfda0085d964ab2d Reviewed-on: https://gerrit.readyset.name/c/readyset/+/9462 Reviewed-by: Sidney Cammeresi <[email protected]> Tested-by: Buildkite CI
1 parent a460da9 commit e1fdf26

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

readyset-psql/tests/fallback.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ async fn setup() -> (tokio_postgres::Config, Handle, ShutdownSender) {
2828
.await
2929
}
3030

31+
#[cfg(feature = "failure_injection")]
32+
macro_rules! assert_last_statement_matches {
33+
($table:expr, $dest:expr, $status:expr, $client:expr) => {
34+
let (matches, err) = last_statement_matches($dest, $status, $client).await;
35+
assert!(
36+
matches,
37+
"EXPLAIN LAST STATEMENT mismatch for query involving table {}: {}",
38+
$table, err
39+
);
40+
};
41+
}
42+
3143
#[tokio::test(flavor = "multi_thread")]
3244
#[tags(serial, postgres_upstream)]
3345
#[slow]
@@ -372,7 +384,7 @@ async fn schema_resolution_with_unreplicated_tables() {
372384
.get::<_, i32>(0);
373385
assert_eq!(result, 2);
374386

375-
assert_last_statement_matches("t", "readyset", "ok", &client).await;
387+
assert_last_statement_matches!("t", "readyset", "ok", &client);
376388

377389
shutdown_tx.shutdown().await;
378390
}
@@ -981,15 +993,6 @@ async fn last_statement_matches(dest: &str, status: &str, client: &Client) -> (b
981993
}
982994
}
983995

984-
#[allow(dead_code)]
985-
async fn assert_last_statement_matches(table: &str, dest: &str, status: &str, client: &Client) {
986-
let (matches, err) = last_statement_matches(dest, status, client).await;
987-
assert!(
988-
matches,
989-
"EXPLAIN LAST STATEMENT mismatch for query involving table {table}: {err}"
990-
);
991-
}
992-
993996
#[cfg(feature = "failure_injection")]
994997
async fn setup_for_replication_failure(client: &Client) {
995998
client
@@ -1014,7 +1017,7 @@ async fn setup_for_replication_failure(client: &Client) {
10141017
sleep().await;
10151018
sleep().await;
10161019

1017-
assert_last_statement_matches("cats", "upstream", "ok", client).await;
1020+
assert_last_statement_matches!("cats", "upstream", "ok", client);
10181021
client
10191022
.simple_query("CREATE CACHE FROM SELECT * FROM cats")
10201023
.await
@@ -1067,7 +1070,7 @@ async fn assert_table_ignored(client: &Client) {
10671070
let mut results = vec![c1, c2];
10681071
results.sort();
10691072
assert_eq!(results, vec!["1", "2"]);
1070-
assert_last_statement_matches(source, "upstream", "ok", client).await;
1073+
assert_last_statement_matches!(source, "upstream", "ok", client);
10711074
}
10721075
}
10731076

0 commit comments

Comments
 (0)