#![cfg(feature = "test-network")]
use freenet_test_network::{BuildProfile, FreenetBinary, NetworkBuilder};
#[test_log::test(tokio::test(flavor = "current_thread", start_paused = true))]
async fn connection_cap_respected() -> anyhow::Result<()> {
let max_connections = freenet::config::DEFAULT_MAX_CONNECTIONS;
let net = NetworkBuilder::new()
.gateways(2)
.peers(6)
.start_stagger(std::time::Duration::from_millis(300))
.require_connectivity(0.9)
.connectivity_timeout(std::time::Duration::from_secs(40))
.binary(FreenetBinary::CurrentCrate(BuildProfile::Debug))
.build()
.await?;
let snapshot = net.collect_diagnostics().await?;
for peer in snapshot.peers {
let count = peer.connected_peer_ids.len();
assert!(
count <= max_connections,
"peer {} exceeds max connections ({} > {})",
peer.peer_id,
count,
max_connections
);
}
Ok(())
}