From 76302ffec0ec4ba45f1754da1ab681a5e5a962c8 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Wed, 17 Jan 2024 12:35:04 +0100 Subject: [PATCH] cli: Attempt to fix flaky test We also move the seed config to the test module. --- radicle-cli/tests/commands.rs | 43 ++++++++++++++++++++++++++++------- radicle/src/node/config.rs | 26 --------------------- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/radicle-cli/tests/commands.rs b/radicle-cli/tests/commands.rs index 52016b81..ae973a24 100644 --- a/radicle-cli/tests/commands.rs +++ b/radicle-cli/tests/commands.rs @@ -26,8 +26,35 @@ const RAD_SEED: &str = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff mod config { use super::*; + use radicle::node::config::{Config, Limits, Network, RateLimit, RateLimits}; use radicle::profile; + /// Configuration for a test seed node. + /// + /// It sets the `RateLimit::capacity` to `usize::MAX` ensuring + /// that there are no rate limits for test nodes, since they all + /// operate on the same IP address. This prevents any announcement + /// messages from being dropped. + pub fn seed(alias: &'static str) -> Config { + Config { + network: Network::Test, + limits: Limits { + rate: RateLimits { + inbound: RateLimit { + fill_rate: 1.0, + capacity: usize::MAX, + }, + outbound: RateLimit { + fill_rate: 1.0, + capacity: usize::MAX, + }, + }, + ..Limits::default() + }, + ..node(alias) + } + } + /// Test node config. pub fn node(alias: &'static str) -> Config { Config { @@ -378,8 +405,8 @@ fn rad_id_collaboration() { let alice = environment.node(Config::test(Alias::new("alice"))); let bob = environment.node(Config::test(Alias::new("bob"))); let eve = environment.node(Config::test(Alias::new("eve"))); - let seed = environment.node(Config::seed(Alias::new("seed"))); - let distrustful = environment.node(Config::seed(Alias::new("distrustful"))); + let seed = environment.node(config::seed("seed")); + let distrustful = environment.node(config::seed("distrustful")); let working = tempfile::tempdir().unwrap(); let working = working.path(); let acme = Id::from_str("z42hL2jL4XNk6K8oHQaSWfMgCL7ji").unwrap(); @@ -1785,15 +1812,16 @@ fn rad_patch_open_explore() { logger::init(log::Level::Debug); let mut environment = Environment::new(); - let mut alice = environment + let seed = environment .node(Config { policy: Policy::Allow, - ..Config::test(Alias::new("alice")) + scope: Scope::All, + ..config::seed("seed") }) .spawn(); let bob = environment.profile(profile::Config { - preferred_seeds: vec![alice.address()], + preferred_seeds: vec![seed.address()], ..config::profile("bob") }); let mut bob = Node::new(bob).spawn(); @@ -1801,10 +1829,9 @@ fn rad_patch_open_explore() { fixtures::repository(&working); + bob.connect(&seed); bob.init("heartwood", "", &working).unwrap(); - bob.connect(&alice); - alice.handle.follow(bob.id, None).unwrap(); - alice.converge([&bob]); + bob.converge([&seed]); test( "examples/rad-patch-open-explore.md", diff --git a/radicle/src/node/config.rs b/radicle/src/node/config.rs index 29a04afa..9281eab7 100644 --- a/radicle/src/node/config.rs +++ b/radicle/src/node/config.rs @@ -227,32 +227,6 @@ impl Config { } } - /// Configuration for a test seed node. - /// - /// It sets the `RateLimit::capacity` to `usize::MAX` ensuring - /// that there are no rate limits for test nodes, since they all - /// operate on the same IP address. This prevents any announcement - /// messages from being dropped. - pub fn seed(alias: Alias) -> Self { - Self { - network: Network::Test, - limits: Limits { - rate: RateLimits { - inbound: RateLimit { - fill_rate: 1.0, - capacity: usize::MAX, - }, - outbound: RateLimit { - fill_rate: 1.0, - capacity: usize::MAX, - }, - }, - ..Limits::default() - }, - ..Self::new(alias) - } - } - pub fn new(alias: Alias) -> Self { Self { alias,