Skip to content

Commit 0218370

Browse files
ddl_vertical_postgresql: add logging to eventually!
Adding more debug logging to eventually! Change-Id: Iaafc0fad282c3c2337fbb33705ce01f22753ed3e Reviewed-on: https://gerrit.readyset.name/c/readyset/+/10520 Reviewed-by: Michael Zink <[email protected]> Tested-by: Buildkite CI
1 parent aeb37f2 commit 0218370

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

readyset-util/src/futures.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::future::Future;
44
use std::panic::AssertUnwindSafe;
55
use std::process;
66

7+
use chrono::{SecondsFormat, Utc};
78
use futures::{FutureExt, TryFutureExt};
89
use tracing::error;
910

@@ -153,6 +154,12 @@ where
153154
})
154155
}
155156

157+
#[doc(hidden)]
158+
pub fn __eventually_warn(message: &str) {
159+
let ts = Utc::now().to_rfc3339_opts(SecondsFormat::Micros, true);
160+
println!("{} {}", ts, message);
161+
}
162+
156163
/// Assert that the given async expression eventually succeeds after a configurable number of
157164
/// tries and sleeping a configurable amount between tries. Useful for testing eventually
158165
/// consistent parts of the system.
@@ -289,7 +296,7 @@ where
289296
/// ```
290297
#[macro_export]
291298
macro_rules! eventually {
292-
($(attempts: $attempts: expr,)? $(sleep: $sleep: expr,)? run_test: { $($test_body: tt)* },
299+
($(attempts: $attempts: expr,)? $(sleep: $sleep: expr,)? $(token: $token: expr,)? run_test: { $($test_body: tt)* },
293300
then_assert: |$test_res: pat_param| $($assert_body: tt)+) => {{
294301
let attempts = 40;
295302
let sleep = std::time::Duration::from_millis(500);
@@ -299,11 +306,21 @@ macro_rules! eventually {
299306

300307

301308
let mut res = None;
309+
let token_opt: Option<&str> = None; $(let token_opt = Some($token);)?
302310
for attempt in 1..=(attempts - 1) {
303311
let $test_res = async { $($test_body)* }.await;
304312
match ::futures::FutureExt::catch_unwind(async { $($assert_body)* }).await {
305313
Err(_) => {
306-
println!("Assertion failed on attempt {attempt}, retrying after delay...");
314+
if let Some(token) = token_opt {
315+
$crate::futures::__eventually_warn(&format!(
316+
"Assertion failed on attempt {attempt} (token: {}), retrying after delay...",
317+
token
318+
));
319+
} else {
320+
$crate::futures::__eventually_warn(&format!(
321+
"Assertion failed on attempt {attempt}, retrying after delay..."
322+
));
323+
}
307324
tokio::time::sleep(sleep).await;
308325
}
309326
Ok(r) => {
@@ -323,7 +340,7 @@ macro_rules! eventually {
323340
}
324341
}
325342
}};
326-
($(attempts: $attempts: expr,)? $(sleep: $sleep: expr,)? run_test: { $($test_body: tt)* },
343+
($(attempts: $attempts: expr,)? $(sleep: $sleep: expr,)? $(token: $token: expr,)? run_test: { $($test_body: tt)* },
327344
then_assert: $($assert_body: tt)+) => {
328345
compile_error!(concat!("`then_assert` must be specified using closure syntax",
329346
"(see `eventually` docs for detail)"))

replicators/tests/ddl_vertical_postgresql.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ impl ModelState for DDLModelState {
942942

943943
let create_cache =
944944
format!("CREATE CACHE ALWAYS FROM SELECT * FROM \"{table_name}\"");
945-
eventually!(run_test: {
945+
eventually!(token: "failed to create cache after creating table", run_test: {
946946
let result = rs_conn.simple_query(&create_cache).await;
947947
AssertUnwindSafe(move || result)
948948
}, then_assert: |result| {
@@ -1004,7 +1004,7 @@ impl ModelState for DDLModelState {
10041004
rs_conn.simple_query(&query).await.unwrap();
10051005
pg_conn.simple_query(&query).await.unwrap();
10061006
let create_cache = format!("CREATE CACHE ALWAYS FROM SELECT * FROM \"{name}\"");
1007-
eventually!(run_test: {
1007+
eventually!(token: "failed to create cache after creating simple view", run_test: {
10081008
let result = rs_conn.simple_query(&create_cache).await;
10091009
AssertUnwindSafe(move || result)
10101010
}, then_assert: |result| {
@@ -1033,7 +1033,7 @@ impl ModelState for DDLModelState {
10331033
rs_conn.simple_query(&query).await.unwrap();
10341034
pg_conn.simple_query(&query).await.unwrap();
10351035
let create_cache = format!("CREATE CACHE ALWAYS FROM SELECT * FROM \"{name}\"");
1036-
eventually!(run_test: {
1036+
eventually!(token: "failed to create cache after creating join view", run_test: {
10371037
let result = rs_conn.simple_query(&create_cache).await;
10381038
AssertUnwindSafe(move || result)
10391039
}, then_assert: |result| {
@@ -1131,7 +1131,8 @@ impl ModelState for DDLModelState {
11311131

11321132
// After each op, check that all table and view contents match
11331133
for relation in self.tables.keys().chain(self.views.keys()) {
1134-
eventually!(run_test: {
1134+
eventually!(token: "results mismatch",
1135+
run_test: {
11351136
let rs_rows = rs_conn
11361137
.query(&format!("SELECT * FROM \"{relation}\""), &[])
11371138
.await
@@ -1154,6 +1155,10 @@ impl ModelState for DDLModelState {
11541155
rs_results.sort_unstable();
11551156
pg_results.sort_unstable();
11561157

1158+
if pg_results != rs_results {
1159+
println!("results mismatch\nrs={:?}\npg={:?}", rs_results, pg_results);
1160+
}
1161+
11571162
assert_eq!(pg_results, rs_results);
11581163
});
11591164
}
@@ -1244,7 +1249,7 @@ async fn recreate_caches_using_type(
12441249
for table in tables_using_type(tables, type_name) {
12451250
let create_cache = format!("CREATE CACHE ALWAYS FROM SELECT * FROM \"{table}\"");
12461251

1247-
eventually!(run_test: {
1252+
eventually!(token: "failed to recreate cache using type", run_test: {
12481253
let result = rs_conn.simple_query(&create_cache).await;
12491254
AssertUnwindSafe(move || result)
12501255
}, then_assert: |result| {

0 commit comments

Comments
 (0)