From a3f8305eb437caa29a65a24a3ec5ab0f0cc80d0e Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Thu, 8 Jun 2023 15:44:30 +0200 Subject: [PATCH] node: Reduce test flakiness Most of the test flakiness was caused by the git-daemon not being able to bind to a port. It seems like using an RNG was not a good enough solution. After this change, tests seem to be passing without issue. --- radicle-node/src/test/environment.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/radicle-node/src/test/environment.rs b/radicle-node/src/test/environment.rs index 2a146e65..6d608a2c 100644 --- a/radicle-node/src/test/environment.rs +++ b/radicle-node/src/test/environment.rs @@ -301,7 +301,13 @@ impl + Signer + Clone> Node { pub fn spawn(self, config: service::Config) -> NodeHandle { let listen = vec![([0, 0, 0, 0], 0).into()]; let proxy = net::SocketAddr::new(net::Ipv4Addr::LOCALHOST.into(), 9050); - let daemon = ([0, 0, 0, 0], fastrand::u16(1025..)).into(); + let daemon: net::SocketAddr = { + // Find free port for git-daemon to bind to. + // This is a somewhat racy solution, though it works much better than assigning a random + // port. + let sock = net::TcpListener::bind("0.0.0.0:0").unwrap(); + ([0, 0, 0, 0], sock.local_addr().unwrap().port()).into() + }; let (_, signals) = chan::bounded(1); let rt = Runtime::init( self.home.clone(),