Skip to content

Commit

Permalink
Integration Test: RandomlyKill wait rpc are ready before send rpc req…
Browse files Browse the repository at this point in the history
…uest
  • Loading branch information
eval-exec committed Aug 4, 2024
1 parent 3c3302f commit 9058b3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,
Expand Down
1 change: 1 addition & 0 deletions test/src/specs/fault_injection/randomly_kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9058b3c

Please sign in to comment.