mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Fix api test in travis (#1757)
* seems to be too slow to start api server, adding retry to client. Fixes #1722 * Add sleep before retry
This commit is contained in:
commit
119b5cfc46
1 changed files with 19 additions and 4 deletions
|
@ -71,9 +71,9 @@ fn test_start_api() {
|
|||
let addr: SocketAddr = server_addr.parse().expect("unable to parse server address");
|
||||
assert!(server.start(addr, router, None).is_ok());
|
||||
let url = format!("http://{}/v1/", server_addr);
|
||||
let index = api::client::get::<Vec<String>>(url.as_str(), None).unwrap();
|
||||
// assert_eq!(index.len(), 2);
|
||||
// assert_eq!(counter.value(), 1);
|
||||
let index = request_with_retry(url.as_str()).unwrap();
|
||||
assert_eq!(index.len(), 2);
|
||||
assert_eq!(counter.value(), 1);
|
||||
assert!(server.stop());
|
||||
thread::sleep(time::Duration::from_millis(1_000));
|
||||
}
|
||||
|
@ -95,7 +95,22 @@ fn test_start_api_tls() {
|
|||
let server_addr = "0.0.0.0:14444";
|
||||
let addr: SocketAddr = server_addr.parse().expect("unable to parse server address");
|
||||
assert!(server.start(addr, router, Some(tls_conf)).is_ok());
|
||||
let index = api::client::get::<Vec<String>>("https://yourdomain.com:14444/v1/", None).unwrap();
|
||||
let index = request_with_retry("https://yourdomain.com:14444/v1/").unwrap();
|
||||
assert_eq!(index.len(), 2);
|
||||
assert!(!server.stop());
|
||||
}
|
||||
|
||||
fn request_with_retry(url: &str) -> Result<Vec<String>, api::Error> {
|
||||
let mut tries = 0;
|
||||
loop {
|
||||
let res = api::client::get::<Vec<String>>(url, None);
|
||||
if res.is_ok() {
|
||||
return res;
|
||||
}
|
||||
if tries > 5 {
|
||||
return res;
|
||||
}
|
||||
tries += 1;
|
||||
thread::sleep(time::Duration::from_millis(500));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue