#[macro_export]
macro_rules! async_assert_eventually {
($check_expr:expr, expect = $expect:expr, max_attempts = $max_attempts:expr, interval = $interval:expr $(,)?) => {{
let mut value = $check_expr;
let mut attempts = 0;
while value != $expect {
attempts += 1;
assert!(
attempts <= $max_attempts,
"assert_eventually assertion failed. Expression did not equal value after {} attempts.",
attempts - 1
);
tokio::time::sleep($interval).await;
value = $check_expr;
}
}};
($check_expr:expr, expect = $expect:expr, max_attempts = $max_attempts:expr, $(,)?) => {{
async_assert_eventually!(
$check_expr,
expect = $expect,
max_attempts = $max_attempts,
interval = std::time::Duration::from_millis(100)
);
}};
($check_expr:expr, expect = $expect:expr $(,)?) => {{
async_assert_eventually!(
$check_expr,
expect = $expect,
max_attempts = 10,
interval = std::time::Duration::from_millis(100)
);
}};
}
#[macro_export]
macro_rules! async_assert {
($check_expr:expr, max_attempts = $max_attempts:expr, interval = $interval:expr $(,)?) => {{
let mut attempts = 0;
while !($check_expr) {
attempts += 1;
assert!(
attempts <= $max_attempts,
"Assertion failed. Expression was not true after {} attempts.",
$max_attempts
);
tokio::time::sleep($interval).await;
}
}};
($check_expr:expr$(,)?) => {{
async_assert!(
$check_expr,
max_attempts = 10,
interval = std::time::Duration::from_millis(100)
)
}};
}