From 5c2bae18c31b75c4539530be167306fd404b5c80 Mon Sep 17 00:00:00 2001 From: Caio Date: Mon, 24 Oct 2022 11:03:09 +0200 Subject: [PATCH] bug: ensure a valid probe state when going idle another missing cleanup. I suspect this is the last as we only have two inactive states and the previous missing one [^1] covered the defunct case [^1]: 907b363ebf3f2444c23a213e0257ea1826983b7e --- src/lib.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 47ed8a8..2d8c0b7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1022,6 +1022,7 @@ where // being switched the Down state since we have little // confidence about our own state at this point. self.timer_token = self.timer_token.wrapping_add(1); + self.probe.clear(); runtime.notify(Notification::Idle); } @@ -2372,6 +2373,34 @@ mod tests { (foca, probed, send_indirect_probe) } + #[test] + fn going_idle_clears_probe_state() { + // Here we'll craft a scenario where a foca instance is in the middle + // of a probe cycle when, for whatever reason, it learns that there + // are no more active members in the cluster (thus going Idle) + + // A foca is probing + let (mut foca, _probed, _send_indirect_probe) = craft_probing_foca(2); + let mut runtime = InMemoryRuntime::new(); + + // Clippy gets it wrong here: can't use just the plain iterator + // otherwise foca remains borrowed + #[allow(clippy::needless_collect)] + let updates = foca + .iter_members() + .cloned() + .map(Member::down) + .collect::>(); + // But somehow all members "disappear" + assert_eq!(Ok(()), foca.apply_many(updates.into_iter(), &mut runtime)); + // Making the instance go idle + expect_notification!(runtime, Notification::::Idle); + + // The probe state should've been cleared now so that when the instance + // resumes operation things are actually functional + assert!(foca.probe().validate(), "invalid probe state") + } + #[test] fn probe_ping_ack_cycle() { let (mut foca, probed, send_indirect_probe) = craft_probing_foca(5);