From ca7231e652ca7abd42dc48ebbc2a82c82a1b637b Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Wed, 6 Aug 2025 11:51:40 +0100 Subject: [PATCH] radicle: Announcer test adapting the replication target The replication target should be constrained to the number of nodes to sync with, if the original value exceeds that number. --- crates/radicle/src/node/sync/announce.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/radicle/src/node/sync/announce.rs b/crates/radicle/src/node/sync/announce.rs index 94880190..d37e8c50 100644 --- a/crates/radicle/src/node/sync/announce.rs +++ b/crates/radicle/src/node/sync/announce.rs @@ -579,7 +579,8 @@ mod test { let config = AnnouncerConfig::public( local, - ReplicationFactor::must_reach(5), // High target that we won't reach with preferred alone + // High target that we won't reach with preferred alone + ReplicationFactor::must_reach(5), preferred_seeds.clone(), BTreeSet::new(), unsynced, @@ -929,6 +930,26 @@ mod test { } } + #[test] + fn announcer_adapts_target_to_reach() { + let local = arbitrary::gen::(0); + // Only 3 nodes available + let unsynced = arbitrary::set::(3..=3) + .into_iter() + .collect::>(); + + let config = AnnouncerConfig::public( + local, + ReplicationFactor::must_reach(5), // Want 5 but only have 3 + BTreeSet::new(), + BTreeSet::new(), + unsynced.clone(), + ); + + let announcer = Announcer::new(config).unwrap(); + assert_eq!(announcer.target().replicas().lower_bound(), 3); + } + #[test] fn announcer_with_replication_factor_zero_and_preferred_seeds() { let local = arbitrary::gen::(0);