mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2025-01-06 05:59:23 +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 {
|
for (ip, _, rpc, zmq) in REMOTE_NODES {
|
||||||
println!("[{}/{}] {} | {} | {}", n, REMOTE_NODE_LENGTH, ip, rpc, zmq);
|
println!("[{}/{}] {} | {} | {}", n, REMOTE_NODE_LENGTH, ip, rpc, zmq);
|
||||||
let client = client.clone();
|
let client = client.clone();
|
||||||
let request = Request::builder()
|
// Try 5 times before failure
|
||||||
.method("POST")
|
let mut i = 1;
|
||||||
.uri("http://".to_string() + ip + ":" + rpc + "/json_rpc")
|
let mut response = loop {
|
||||||
.header("User-Agent", rand_user_agent)
|
let request = Request::builder()
|
||||||
.body(hyper::Body::from(r#"{"jsonrpc":"2.0","id":"0","method":"get_info"}"#))
|
.method("POST")
|
||||||
.unwrap();
|
.uri("http://".to_string() + ip + ":" + rpc + "/json_rpc")
|
||||||
let mut response = client.request(request).await.unwrap();
|
.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 body = hyper::body::to_bytes(response.body_mut()).await.unwrap();
|
||||||
let getinfo: GetInfo = serde_json::from_slice(&body).unwrap();
|
let getinfo: GetInfo = serde_json::from_slice(&body).unwrap();
|
||||||
assert!(getinfo.id == "0");
|
assert!(getinfo.id == "0");
|
||||||
|
|
Loading…
Reference in a new issue