Skip to content

Commit bc07434

Browse files
committed
Wait for RPC readiness before running test setup
The wait_for_ready check only verified P2P port connectivity. Dashd can accept P2P connections while RPC still returns code -28 (initializing). Now also polls get_blockchain_info until it succeeds.
1 parent 69a53e2 commit bc07434

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

dash-spv/src/test_utils/node.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,32 @@ impl DashCoreNode {
200200
let check_interval = Duration::from_millis(500);
201201

202202
let result = timeout(max_wait, async {
203+
// Wait for the P2P port to accept connections
203204
loop {
204205
let addr = SocketAddr::from((Ipv4Addr::new(127, 0, 0, 1), self.config.p2p_port));
205206
if tokio::net::TcpStream::connect(addr).await.is_ok() {
206-
return true;
207+
break;
208+
}
209+
sleep(check_interval).await;
210+
}
211+
212+
// Wait for RPC to be fully responsive (not just "warming up")
213+
loop {
214+
let url = format!("http://127.0.0.1:{}", self.config.rpc_port);
215+
let cookie_path = self.config.datadir.join("regtest/.cookie");
216+
if let Ok(auth) = cookie_path
217+
.exists()
218+
.then(|| Auth::CookieFile(cookie_path))
219+
.ok_or(())
220+
{
221+
if let Ok(client) = Client::new(&url, auth) {
222+
match client.get_blockchain_info() {
223+
Ok(_) => return true,
224+
Err(e) => {
225+
tracing::debug!("RPC not ready yet: {}", e);
226+
}
227+
}
228+
}
207229
}
208230
sleep(check_interval).await;
209231
}

0 commit comments

Comments
 (0)