Skip to content

Commit

Permalink
bug: ensure a valid probe state when going idle
Browse files Browse the repository at this point in the history
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]: 907b363
  • Loading branch information
caio committed Oct 24, 2022
1 parent 57dad53 commit 5c2bae1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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::<Vec<_>>();
// 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::<ID>::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);
Expand Down

0 comments on commit 5c2bae1

Please sign in to comment.