From 278ca3cd21397ffad07f0874b80b77f41088a3f2 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 6 Nov 2026 04:15:59 +0100 Subject: swarm neighbours --- src/swarm/topology/tests.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/swarm/topology/tests.rs') diff --git a/src/swarm/topology/tests.rs b/src/swarm/topology/tests.rs index 4069c0e..1b9c75d 100644 --- a/src/swarm/topology/tests.rs +++ b/src/swarm/topology/tests.rs @@ -467,3 +467,25 @@ fn bench_writer_trees() { } } } + +/// The neighbours a swarm records count; without one, or with one out of range, the +/// node's own. +#[test] +fn the_swarms_neighbours_count() { + use crate::document::testing::change; + use crate::document::{Document, store}; + let mut doc = Document::new(); + assert_eq!(swarm_neighbours(&doc, 12), 12); + for (recorded, expected) in [ + (serde_json::json!(8), 8), + (serde_json::json!(1), 12), + (serde_json::json!(1000), 12), + (serde_json::json!("eight"), 12), + ] { + change(&mut doc, |doc| { + store::write_path(doc, &neighbours_path(), &recorded).unwrap() + }); + assert_eq!(swarm_neighbours(&doc, 12), expected, "{recorded}"); + } + assert!(affects_neighbours(&neighbours_path())); +} -- cgit v1.3.1