summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/swarm/topology.rs54
1 files 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<String> = 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<String> = 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);
}
}
}