From 9c1a6bed7be6f414c722016b23adaab95814f115 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 22 Jun 2021 05:07:33 +0000 Subject: [PATCH] Fix flaky optimistic violation detection cluster test (#18027) (#18126) * Fix flaky optimistic violation detection cluster test * Add small sleep to avoid tight loop (cherry picked from commit 423e0d90ee19dfad9c5f46d9f51de95147a47dc5) Co-authored-by: Ashwin Sekar --- local-cluster/tests/local_cluster.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/local-cluster/tests/local_cluster.rs b/local-cluster/tests/local_cluster.rs index 7d32cb9770..6e7a241580 100644 --- a/local-cluster/tests/local_cluster.rs +++ b/local-cluster/tests/local_cluster.rs @@ -2183,11 +2183,21 @@ fn test_optimistic_confirmation_violation_detection() { OptimisticConfirmationVerifier::format_optimistic_confirmed_slot_violation_log( prev_voted_slot, ); + // Violation detection thread can be behind so poll logs up to 10 seconds if let Some(mut buf) = buf { + let start = Instant::now(); + let mut success = false; let mut output = String::new(); - buf.read_to_string(&mut output).unwrap(); - assert!(output.contains(&expected_log)); + while start.elapsed().as_secs() < 10 { + buf.read_to_string(&mut output).unwrap(); + if output.contains(&expected_log) { + success = true; + break; + } + sleep(Duration::from_millis(10)); + } print!("{}", output); + assert!(success); } else { panic!("dumped log and disabled testing"); }