aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/working_links.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/working_links.rs')
-rw-r--r--src/swarm/working_links.rs26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/swarm/working_links.rs b/src/swarm/working_links.rs
index 621ea6c..6f07375 100644
--- a/src/swarm/working_links.rs
+++ b/src/swarm/working_links.rs
@@ -43,6 +43,17 @@ const UP_FOR: u32 = 1;
#[derive(Default)]
pub(crate) struct Pending {
since: HashMap<String, Instant>,
+ /// Checks done (`check`), for the benchmark to wait for one (`settled`).
+ #[cfg(test)]
+ checks: u64,
+}
+
+/// How many checks were done, and whether none of our links differs from our record
+/// (nothing awaits its hold).
+#[cfg(test)]
+pub(crate) fn settled(state: &AppState) -> (u64, bool) {
+ let pending = state.working_links.lock_or_recover();
+ (pending.checks, pending.since.is_empty())
}
/// With the peer worker's periodic pass (every 5 s): whom we reach now, against the
@@ -76,13 +87,14 @@ pub(crate) async fn check(state: &AppState) {
let replica = state.doc.read().await;
members::links(&replica.doc, &me)
};
- let next = decide(
- &mut state.working_links.lock_or_recover(),
- &recorded,
- &links,
- now,
- state.timing.keepalive,
- );
+ let next = {
+ let mut pending = state.working_links.lock_or_recover();
+ #[cfg(test)]
+ {
+ pending.checks += 1;
+ }
+ decide(&mut pending, &recorded, &links, now, state.timing.keepalive)
+ };
if next == recorded {
return;
}