diff --git a/api/tests/rest.rs b/api/tests/rest.rs index 2ba8e5c36..e6e564819 100644 --- a/api/tests/rest.rs +++ b/api/tests/rest.rs @@ -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::>(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::>("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, api::Error> { + let mut tries = 0; + loop { + let res = api::client::get::>(url, None); + if res.is_ok() { + return res; + } + if tries > 5 { + return res; + } + tries += 1; + thread::sleep(time::Duration::from_millis(500)); + } +}