Add network timeouts and fix tests

test_rpc_send_tx could fail if it didn't succeed on the first try
* add some retries to consistently pass
This commit is contained in:
Stephen Akridge 2019-01-15 15:06:50 -08:00 committed by sakridge
parent 590b88f718
commit 8e67a18551
1 changed files with 20 additions and 10 deletions

View File

@ -765,7 +765,7 @@ mod tests {
let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap(); let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap();
let signature = &json["result"]; let signature = &json["result"];
sleep(Duration::from_millis(500)); let mut confirmed_tx = false;
let client = reqwest::Client::new(); let client = reqwest::Client::new();
let request = json!({ let request = json!({
@ -774,16 +774,26 @@ mod tests {
"method": "confirmTransaction", "method": "confirmTransaction",
"params": [signature], "params": [signature],
}); });
let mut response = client
.post(&rpc_string)
.header(CONTENT_TYPE, "application/json")
.body(request.to_string())
.send()
.unwrap();
let response_json_text = response.text().unwrap();
let json: Value = serde_json::from_str(&response_json_text).unwrap();
assert_eq!(true, json["result"]); for _ in 0..5 {
let mut response = client
.post(&rpc_string)
.header(CONTENT_TYPE, "application/json")
.body(request.to_string())
.send()
.unwrap();
let response_json_text = response.text().unwrap();
let json: Value = serde_json::from_str(&response_json_text).unwrap();
if true == json["result"] {
confirmed_tx = true;
break;
}
sleep(Duration::from_millis(250));
}
assert!(confirmed_tx);
server.close().unwrap(); server.close().unwrap();
remove_dir_all(ledger_path).unwrap(); remove_dir_all(ledger_path).unwrap();