mirror of
https://github.com/hinto-janai/gupax.git
synced 2024-11-17 01:37:52 +00:00
node: try 5 times before failing test
This commit is contained in:
parent
c5edfa5593
commit
a1c2814a3d
1 changed files with 19 additions and 7 deletions
26
src/node.rs
26
src/node.rs
|
@ -475,13 +475,25 @@ mod test {
|
|||
for (ip, _, rpc, zmq) in REMOTE_NODES {
|
||||
println!("[{}/{}] {} | {} | {}", n, REMOTE_NODE_LENGTH, ip, rpc, zmq);
|
||||
let client = client.clone();
|
||||
let request = Request::builder()
|
||||
.method("POST")
|
||||
.uri("http://".to_string() + ip + ":" + rpc + "/json_rpc")
|
||||
.header("User-Agent", rand_user_agent)
|
||||
.body(hyper::Body::from(r#"{"jsonrpc":"2.0","id":"0","method":"get_info"}"#))
|
||||
.unwrap();
|
||||
let mut response = client.request(request).await.unwrap();
|
||||
// Try 5 times before failure
|
||||
let mut i = 1;
|
||||
let mut response = loop {
|
||||
let request = Request::builder()
|
||||
.method("POST")
|
||||
.uri("http://".to_string() + ip + ":" + rpc + "/json_rpc")
|
||||
.header("User-Agent", rand_user_agent)
|
||||
.body(hyper::Body::from(r#"{"jsonrpc":"2.0","id":"0","method":"get_info"}"#))
|
||||
.unwrap();
|
||||
match client.request(request).await {
|
||||
Ok(response) => break response,
|
||||
Err(e) => {
|
||||
println!("{:#?}", e);
|
||||
if i > 5 { panic!("Node failure: {}:{}:{}", ip, rpc, zmq); }
|
||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
let body = hyper::body::to_bytes(response.body_mut()).await.unwrap();
|
||||
let getinfo: GetInfo = serde_json::from_slice(&body).unwrap();
|
||||
assert!(getinfo.id == "0");
|
||||
|
|
Loading…
Reference in a new issue