Skip to content

Commit f257557

Browse files
authored
Fix test_readiness_updates flaky test (#6053)
1 parent 1c3ff5d commit f257557

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

quickwit/quickwit-common/src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,32 @@ pub fn no_color() -> bool {
188188
matches!(env::var("NO_COLOR"), Ok(value) if !value.is_empty())
189189
}
190190

191+
#[macro_export]
192+
macro_rules! assert_eventually {
193+
($cond:expr, $timeout:expr, $interval:expr) => {
194+
let start = std::time::Instant::now();
195+
loop {
196+
if $cond {
197+
break;
198+
}
199+
if start.elapsed() > $timeout {
200+
panic!(
201+
"assertion failed: condition `{}` never became true within {} ms",
202+
stringify!($cond),
203+
$timeout.as_millis()
204+
);
205+
}
206+
tokio::time::sleep($interval).await;
207+
}
208+
};
209+
($cond:expr, $timeout:expr) => {
210+
assert_eventually!($cond, $timeout, std::time::Duration::from_millis(50));
211+
};
212+
($cond:expr) => {
213+
assert_eventually!($cond, std::time::Duration::from_secs(1));
214+
};
215+
}
216+
191217
#[macro_export]
192218
macro_rules! ignore_error_kind {
193219
($kind:path, $expr:expr) => {

quickwit/quickwit-serve/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,8 +1353,8 @@ async fn check_cluster_configuration(
13531353
#[cfg(test)]
13541354
mod tests {
13551355
use quickwit_cluster::{ChannelTransport, ClusterNode, create_cluster_for_test};
1356-
use quickwit_common::ServiceStream;
13571356
use quickwit_common::uri::Uri;
1357+
use quickwit_common::{ServiceStream, assert_eventually};
13581358
use quickwit_config::SearcherConfig;
13591359
use quickwit_metastore::{IndexMetadata, metastore_for_test};
13601360
use quickwit_proto::indexing::IndexingTask;
@@ -1472,16 +1472,14 @@ mod tests {
14721472

14731473
metastore_readiness_tx.send(true).unwrap();
14741474
ingester_status_tx.send(IngesterStatus::Ready).unwrap();
1475-
tokio::time::sleep(Duration::from_millis(25)).await;
1476-
assert!(cluster.is_self_node_ready().await);
1475+
assert_eventually!(cluster.is_self_node_ready().await);
14771476

14781477
let request = tonic::Request::new(HealthCheckRequest::default());
14791478
let response = health_client.check(request).await.unwrap().into_inner();
14801479
assert_eq!(response.status(), ServingStatus::Serving.into());
14811480

14821481
metastore_readiness_tx.send(false).unwrap();
1483-
tokio::time::sleep(Duration::from_millis(25)).await;
1484-
assert!(!cluster.is_self_node_ready().await);
1482+
assert_eventually!(!cluster.is_self_node_ready().await);
14851483

14861484
let request = tonic::Request::new(HealthCheckRequest::default());
14871485
let response = health_client.check(request).await.unwrap().into_inner();

0 commit comments

Comments
 (0)