From 07d6bca08f0ef8deb752eb17e87ecca1e2c441ae Mon Sep 17 00:00:00 2001 From: knight42 Date: Sun, 22 Oct 2017 13:09:03 +0800 Subject: [PATCH] fix: tests::support::server If the length of expected header is accidentally larger than the length of the actual header, `socket.read()` will keep pulling bytes from the socket which could no longer produce any, hence the later calls of `socket.read` will return a `WouldBlock` Error. --- tests/support/server.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/support/server.rs b/tests/support/server.rs index 9e1a7f3..145bbf0 100644 --- a/tests/support/server.rs +++ b/tests/support/server.rs @@ -51,7 +51,10 @@ pub fn spawn(txns: Vec) -> Server { let mut n = 0; while n < expected.len() { - n += socket.read(&mut buf).unwrap(); + match socket.read(&mut buf[n..]) { + Ok(0) | Err(_) => break, + Ok(nread) => n += nread, + } } match (::std::str::from_utf8(&expected), ::std::str::from_utf8(&buf[..n])) {