Skip to content

Commit

Permalink
Loosen timeout restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed May 30, 2015
1 parent 494901a commit b5c6c7e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
16 changes: 6 additions & 10 deletions src/libstd/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,17 +933,15 @@ mod tests {
let listener = t!(TcpListener::bind(&addr));

let mut stream = t!(TcpStream::connect(&("localhost", addr.port())));
t!(stream.set_read_timeout(Some(Duration::from_millis(10))));
t!(stream.set_read_timeout(Some(Duration::from_millis(1000))));

let mut buf = [0; 10];
let wait = Duration::span(|| {
let kind = stream.read(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
});
assert!(wait > Duration::from_millis(5));
// windows will sometimes extend this by ~500ms, so we'll just take the
// fact that we did time out as a win :(
assert!(cfg!(windows) || wait < Duration::from_millis(15));
assert!(wait > Duration::from_millis(400));
assert!(wait < Duration::from_millis(1600));
}

#[test]
Expand All @@ -952,7 +950,7 @@ mod tests {
let listener = t!(TcpListener::bind(&addr));

let mut stream = t!(TcpStream::connect(&("localhost", addr.port())));
t!(stream.set_read_timeout(Some(Duration::from_millis(10))));
t!(stream.set_read_timeout(Some(Duration::from_millis(1000))));

let mut other_end = t!(listener.accept()).0;
t!(other_end.write_all(b"hello world"));
Expand All @@ -965,9 +963,7 @@ mod tests {
let kind = stream.read(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
});
assert!(wait > Duration::from_millis(5));
// windows will sometimes extend this by ~500ms, so we'll just take the
// fact that we did time out as a win :(
assert!(cfg!(windows) || wait < Duration::from_millis(15));
assert!(wait > Duration::from_millis(400));
assert!(wait < Duration::from_millis(1600));
}
}
16 changes: 6 additions & 10 deletions src/libstd/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,25 +389,23 @@ mod tests {
let addr = next_test_ip4();

let mut stream = t!(UdpSocket::bind(&addr));
t!(stream.set_read_timeout(Some(Duration::from_millis(10))));
t!(stream.set_read_timeout(Some(Duration::from_millis(1000))));

let mut buf = [0; 10];
let wait = Duration::span(|| {
let kind = stream.recv_from(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
});
assert!(wait > Duration::from_millis(5));
// windows will sometimes extend this by ~500ms, so we'll just take the
// fact that we did time out as a win :(
assert!(cfg!(windows) || wait < Duration::from_millis(15));
assert!(wait > Duration::from_millis(400));
assert!(wait < Duration::from_millis(1600));
}

#[test]
fn test_read_with_timeout() {
let addr = next_test_ip4();

let mut stream = t!(UdpSocket::bind(&addr));
t!(stream.set_read_timeout(Some(Duration::from_millis(10))));
t!(stream.set_read_timeout(Some(Duration::from_millis(1000))));

t!(stream.send_to(b"hello world", &addr));

Expand All @@ -419,9 +417,7 @@ mod tests {
let kind = stream.recv_from(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
});
assert!(wait > Duration::from_millis(5));
// windows will sometimes extend this by ~500ms, so we'll just take the
// fact that we did time out as a win :(
assert!(cfg!(windows) || wait < Duration::from_millis(15));
assert!(wait > Duration::from_millis(400));
assert!(wait < Duration::from_millis(1600));
}
}

0 comments on commit b5c6c7e

Please sign in to comment.