@@ -2230,6 +2230,20 @@ fn zebra_tracing_conflict() -> Result<()> {
22302230 Ok ( ( ) )
22312231}
22322232
2233+ fn wait_until_listening ( addr : std:: net:: SocketAddr , timeout : std:: time:: Duration ) -> bool {
2234+ use std:: net:: TcpStream ;
2235+ use std:: time:: { Duration , Instant } ;
2236+
2237+ let start = Instant :: now ( ) ;
2238+ while start. elapsed ( ) < timeout {
2239+ if TcpStream :: connect_timeout ( & addr, Duration :: from_millis ( 150 ) ) . is_ok ( ) {
2240+ return true ;
2241+ }
2242+ std:: thread:: sleep ( Duration :: from_millis ( 50 ) ) ;
2243+ }
2244+ false
2245+ }
2246+
22332247/// Start 2 zebrad nodes using the same RPC listener port, but different
22342248/// state directories and Zcash listener ports. The first node should get
22352249/// exclusive use of the port. The second node will panic.
@@ -2250,18 +2264,28 @@ fn zebra_rpc_conflict() -> Result<()> {
22502264 //
22512265 // This is the required setting to detect port conflicts.
22522266 let mut config = random_known_rpc_port_config ( false , & Mainnet ) ?;
2267+ let listen_addr = config
2268+ . rpc
2269+ . listen_addr
2270+ . expect ( "random_known_rpc_port_config must set rpc.listen_addr" ) ;
22532271
22542272 let dir1 = testdir ( ) ?. with_config ( & mut config) ?;
2255- let regex1 = regex:: escape ( & format ! (
2256- r"Opened RPC endpoint at {}" ,
2257- config. rpc. listen_addr. unwrap( ) ,
2258- ) ) ;
2273+ let regex1 = regex:: escape ( & format ! ( r"Opened RPC endpoint at {}" , listen_addr, ) ) ;
2274+
2275+ use std:: time:: Duration ;
2276+
2277+ const RPC_READY_TIMEOUT : Duration = Duration :: from_secs ( 5 ) ;
2278+ assert ! (
2279+ wait_until_listening( listen_addr, RPC_READY_TIMEOUT ) ,
2280+ "RPC endpoint did not become connectable at {} within {:?}" ,
2281+ listen_addr,
2282+ RPC_READY_TIMEOUT
2283+ ) ;
22592284
22602285 // From another folder create a configuration with the same endpoint.
22612286 // `rpc.listen_addr` will be the same in the 2 nodes.
22622287 // But they will have different Zcash listeners (auto port) and states (ephemeral)
22632288 let dir2 = testdir ( ) ?. with_config ( & mut config) ?;
2264-
22652289 check_config_conflict ( dir1, regex1. as_str ( ) , dir2, "Address already in use" ) ?;
22662290
22672291 Ok ( ( ) )
0 commit comments