diff --git a/test/src/rpc.rs b/test/src/rpc.rs index 3ce2ed564c..2f91be7e83 100644 --- a/test/src/rpc.rs +++ b/test/src/rpc.rs @@ -173,6 +173,16 @@ impl RpcClient { .expect("rpc call set_ban") } + pub fn wait_rpc_ready(&self) { + let now = std::time::Instant::now(); + while self.inner.get_tip_block_number().is_err() { + std::thread::sleep(std::time::Duration::from_millis(100)); + if now.elapsed() > std::time::Duration::from_secs(60) { + panic!("wait rpc ready timeout"); + } + } + } + pub fn get_block_template( &self, bytes_limit: Option, diff --git a/test/src/specs/fault_injection/randomly_kill.rs b/test/src/specs/fault_injection/randomly_kill.rs index b58670c230..358c81bd9d 100644 --- a/test/src/specs/fault_injection/randomly_kill.rs +++ b/test/src/specs/fault_injection/randomly_kill.rs @@ -12,6 +12,7 @@ impl Spec for RandomlyKill { let mut rng = thread_rng(); let node = &mut nodes[0]; for _ in 0..rng.gen_range(10..20) { + node.rpc_client().wait_rpc_ready(); let n = rng.gen_range(0..10); // TODO: the kill of child process and mining are actually sequential here // We need to find some way to so these two things in parallel.