From f1819c2e3d542e191b396e8aa3f4a56b600449ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=82=8E=E6=B3=BC?= Date: Tue, 7 Nov 2023 09:34:26 +0800 Subject: [PATCH] Refactor: await the reporting of the replication status in the test case 'add_learner_non_blocking'. In this case, a replication failure status is supposed to be reported to the matrix. But sometimes it times out before the failure report can be delivered. To address this issue, just extend the time out duration. --- tests/tests/membership/t11_add_learner.rs | 27 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/tests/membership/t11_add_learner.rs b/tests/tests/membership/t11_add_learner.rs index db3d66f2e..d193bef62 100644 --- a/tests/tests/membership/t11_add_learner.rs +++ b/tests/tests/membership/t11_add_learner.rs @@ -132,12 +132,27 @@ async fn add_learner_non_blocking() -> Result<()> { let raft = router.get_raft_handle(&0)?; raft.add_learner(1, (), false).await?; - sleep(Duration::from_millis(500)).await; - - let metrics = router.get_raft_handle(&0)?.metrics().borrow().clone(); - let repl = metrics.replication.as_ref().unwrap(); - let n1_repl = repl.get(&1); - assert_eq!(Some(&None), n1_repl, "no replication state to the learner is reported"); + let n = 6; + for i in 0..=n { + if i == n { + unreachable!("no replication status is reported to metrics!"); + } + + let metrics = router.get_raft_handle(&0)?.metrics().borrow().clone(); + let repl = metrics.replication.as_ref().unwrap(); + + // The result is Some(&None) when there is no success replication is made, + // and is None if no replication attempt is made(no success or failure is reported to metrics). + let n1_repl = repl.get(&1); + if n1_repl.is_none() { + tracing::info!("--- no replication attempt is made, sleep and retry: {}-th attempt", i); + + sleep(Duration::from_millis(500)).await; + continue; + } + assert_eq!(Some(&None), n1_repl, "no replication state to the learner is reported"); + break; + } } Ok(())