From c102987ebccc90706139e9c8cbc4e8a5323e9aa4 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 26 Oct 2026 23:08:44 +0100 Subject: add smaller topology test --- src/swarm/topology.rs | 54 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/src/swarm/topology.rs b/src/swarm/topology.rs index 0617fc5..f8a1c30 100644 --- a/src/swarm/topology.rs +++ b/src/swarm/topology.rs @@ -611,28 +611,44 @@ mod tests { ); } - #[test] - fn hub_degree_is_bounded_however_few_stable_members() { + /// A hub's degree in a swarm of `n` with `stable_count` stable members stays within + /// the bound. + fn hub_degree_is_bounded(n: usize, stable_count: usize) { // Few stable members among many: without the fan-in budget each would be chosen // by most of the swarm (about 130 neighbours with 10 of 250). With it, a hub has // at most the budget plus the links others choose by pair score and the ring. - for (n, stable_count) in [(250, 10), (1000, 10), (1000, 20)] { - let k = 12; - let ms = members(n); - let stable: BTreeSet = ms.iter().step_by(n / stable_count).cloned().collect(); - let is_stable = |m: &str| stable.contains(m); - let g = super::graph(&ms, k, &all_reachable, &is_stable); - assert!(connected(&g), "n={n} stable={stable_count}"); - let hub_max = g - .iter() - .filter(|(m, _)| stable.contains(*m)) - .map(|(_, ns)| ns.len()) - .max() - .unwrap(); - assert!( - hub_max <= 8 * k, - "n={n} stable={stable_count}: a stable member has {hub_max} neighbours" - ); + let k = 12; + let ms = members(n); + let stable: BTreeSet = ms.iter().step_by(n / stable_count).cloned().collect(); + let is_stable = |m: &str| stable.contains(m); + let g = super::graph(&ms, k, &all_reachable, &is_stable); + assert!(connected(&g), "n={n} stable={stable_count}"); + let hub_max = g + .iter() + .filter(|(m, _)| stable.contains(*m)) + .map(|(_, ns)| ns.len()) + .max() + .unwrap(); + assert!( + hub_max <= 8 * k, + "n={n} stable={stable_count}: a stable member has {hub_max} neighbours" + ); + } + + #[test] + fn hub_degree_is_bounded_however_few_stable_members() { + for (n, stable_count) in [(250, 10), (400, 5)] { + hub_degree_is_bounded(n, stable_count); + } + } + + /// The same at the sizes the bound was designed for; slow in debug builds, so run + /// on request (`cargo test --release -- --ignored`). + #[test] + #[ignore] + fn hub_degree_is_bounded_in_large_swarms() { + for (n, stable_count) in [(1000, 10), (1000, 20), (2000, 20)] { + hub_degree_is_bounded(n, stable_count); } } } -- cgit v1.3.1