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.
This commit is contained in:
knight42
2017-10-22 13:09:03 +08:00
parent 2bd558d8c7
commit 07d6bca08f

View File

@@ -51,7 +51,10 @@ pub fn spawn(txns: Vec<Txn>) -> 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])) {