Skip to content

Commit

Permalink
tests(client): improve panic message when client tests fail
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Sep 12, 2017
1 parent 3dc2228 commit 21de6b6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,26 @@ macro_rules! test {

let (tx, rx) = oneshot::channel();

thread::spawn(move || {
let thread = thread::Builder::new()
.name(format!("tcp-server<{}>", stringify!($name)));
thread.spawn(move || {
let mut inc = server.accept().unwrap().0;
inc.set_read_timeout(Some(Duration::from_secs(5))).unwrap();
inc.set_write_timeout(Some(Duration::from_secs(5))).unwrap();
let expected = format!($server_expected, addr=addr);
let mut buf = [0; 4096];
let mut n = 0;
while n < buf.len() && n < expected.len() {
n += inc.read(&mut buf[n..]).unwrap();
n += match inc.read(&mut buf[n..]) {
Ok(n) => n,
Err(e) => panic!("failed to read request, partialy read = {:?}, error: {}", s(&buf[..n]), e),
};
}
assert_eq!(s(&buf[..n]), expected);

inc.write_all($server_reply.as_ref()).unwrap();
let _ = tx.send(());
});
}).unwrap();

let rx = rx.map_err(|_| hyper::Error::Io(io::Error::new(io::ErrorKind::Other, "thread panicked")));

Expand Down

0 comments on commit 21de6b6

Please sign in to comment.