From 915766c7bfb72e420f6702fe1b2267399d48ede8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Wed, 9 Nov 2016 18:26:35 +0100 Subject: [PATCH] Fix spurious signer tests failures (#3312) * Increasing sleep time for signer tests * Attempt re-connections instead of delaying tests execution --- devtools/src/http_client.rs | 23 ++++++++++++++++++++++- signer/src/tests/mod.rs | 3 +-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/devtools/src/http_client.rs b/devtools/src/http_client.rs index acba2989e..2440a7cda 100644 --- a/devtools/src/http_client.rs +++ b/devtools/src/http_client.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use std::thread; use std::time::Duration; use std::io::{Read, Write}; use std::str::{self, Lines}; @@ -42,8 +43,28 @@ pub fn read_block(lines: &mut Lines, all: bool) -> String { block } +fn connect(address: &SocketAddr) -> TcpStream { + let mut retries = 0; + let mut last_error = None; + while retries < 10 { + retries += 1; + + let res = TcpStream::connect(address); + match res { + Ok(stream) => { + return stream; + }, + Err(e) => { + last_error = Some(e); + thread::sleep(Duration::from_millis(retries * 10)); + } + } + } + panic!("Unable to connect to the server. Last error: {:?}", last_error); +} + pub fn request(address: &SocketAddr, request: &str) -> Response { - let mut req = TcpStream::connect(address).unwrap(); + let mut req = connect(address); req.set_read_timeout(Some(Duration::from_secs(1))).unwrap(); req.write_all(request.as_bytes()).unwrap(); diff --git a/signer/src/tests/mod.rs b/signer/src/tests/mod.rs index 9b85f1554..d442a7e0d 100644 --- a/signer/src/tests/mod.rs +++ b/signer/src/tests/mod.rs @@ -16,7 +16,7 @@ use std::ops::{Deref, DerefMut}; use std::thread; -use std::time::{self, Duration}; +use std::time; use std::sync::Arc; use devtools::{http_client, RandomTempPath}; use rpc::ConfirmationsQueue; @@ -50,7 +50,6 @@ pub fn serve() -> (Server, usize, GuardedAuthCodes) { let builder = ServerBuilder::new(queue, path.to_path_buf()); let port = 35000 + rand::random::() % 10000; let res = builder.start(format!("127.0.0.1:{}", port).parse().unwrap()).unwrap(); - thread::sleep(Duration::from_millis(25)); (res, port, GuardedAuthCodes { authcodes: AuthCodes::from_file(&path).unwrap(),