From 8588b7e0aa4fa84232a82dd2fd81ea9ff84f61e4 Mon Sep 17 00:00:00 2001 From: hashmap Date: Tue, 16 Oct 2018 17:27:04 +0200 Subject: [PATCH 1/2] Fix api test in travis It seems to be too slow to start api server, adding retry to client. Fixes #1722 --- api/tests/rest.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/api/tests/rest.rs b/api/tests/rest.rs index 2ba8e5c36..398b825ec 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,21 @@ 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; + } +} From 7eb84f767586d53bf721a0dc0fd4e11e327d21e3 Mon Sep 17 00:00:00 2001 From: hashmap Date: Tue, 16 Oct 2018 19:43:27 +0200 Subject: [PATCH 2/2] Add sleep before retry --- api/tests/rest.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/api/tests/rest.rs b/api/tests/rest.rs index 398b825ec..e6e564819 100644 --- a/api/tests/rest.rs +++ b/api/tests/rest.rs @@ -111,5 +111,6 @@ fn request_with_retry(url: &str) -> Result, api::Error> { return res; } tries += 1; + thread::sleep(time::Duration::from_millis(500)); } }