Add tests ensuring zero-Duration timeouts result in errors.

Part of https://github.com/rust-lang/rust/issues/48311
This commit is contained in:
Corey Farwell
2018-02-18 16:08:48 -05:00
parent 1ad094d81c
commit d17d645ad7
3 changed files with 77 additions and 1 deletions

View File

@@ -1024,6 +1024,23 @@ mod tests {
assert!(start.elapsed() > Duration::from_millis(400));
}
// Ensure the `set_read_timeout` and `set_write_timeout` calls return errors
// when passed zero Durations
#[test]
fn test_timeout_zero_duration() {
let addr = next_test_ip4();
let socket = t!(UdpSocket::bind(&addr));
let result = socket.set_write_timeout(Some(Duration::new(0, 0)));
let err = result.unwrap_err();
assert_eq!(err.kind(), ErrorKind::InvalidInput);
let result = socket.set_read_timeout(Some(Duration::new(0, 0)));
let err = result.unwrap_err();
assert_eq!(err.kind(), ErrorKind::InvalidInput);
}
#[test]
fn connect_send_recv() {
let addr = next_test_ip4();