Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deal with EINTR in net timeout tests #56394

Merged
merged 1 commit into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/libstd/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1548,8 +1548,9 @@ mod tests {

let mut buf = [0; 10];
let start = Instant::now();
let kind = stream.read(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
let kind = stream.read_exact(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut,
"unexpected_error: {:?}", kind);
assert!(start.elapsed() > Duration::from_millis(400));
drop(listener);
}
Expand All @@ -1570,8 +1571,9 @@ mod tests {
assert_eq!(b"hello world", &buf[..]);

let start = Instant::now();
let kind = stream.read(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
let kind = stream.read_exact(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut,
"unexpected_error: {:?}", kind);
assert!(start.elapsed() > Duration::from_millis(400));
drop(listener);
}
Expand Down
20 changes: 16 additions & 4 deletions src/libstd/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,8 +1030,14 @@ mod tests {
let mut buf = [0; 10];

let start = Instant::now();
let kind = stream.recv_from(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
loop {
let kind = stream.recv_from(&mut buf).err().expect("expected error").kind();
if kind != ErrorKind::Interrupted {
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut,
"unexpected_error: {:?}", kind);
break;
}
}
assert!(start.elapsed() > Duration::from_millis(400));
}

Expand All @@ -1049,8 +1055,14 @@ mod tests {
assert_eq!(b"hello world", &buf[..]);

let start = Instant::now();
let kind = stream.recv_from(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut);
loop {
let kind = stream.recv_from(&mut buf).err().expect("expected error").kind();
if kind != ErrorKind::Interrupted {
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut,
"unexpected_error: {:?}", kind);
break;
}
}
assert!(start.elapsed() > Duration::from_millis(400));
}

Expand Down
10 changes: 6 additions & 4 deletions src/libstd/sys/unix/ext/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1654,8 +1654,9 @@ mod test {
or_panic!(stream.set_read_timeout(Some(Duration::from_millis(1000))));

let mut buf = [0; 10];
let kind = stream.read(&mut buf).err().expect("expected error").kind();
assert!(kind == io::ErrorKind::WouldBlock || kind == io::ErrorKind::TimedOut);
let kind = stream.read_exact(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut,
"unexpected_error: {:?}", kind);
}

#[test]
Expand All @@ -1675,8 +1676,9 @@ mod test {
or_panic!(stream.read(&mut buf));
assert_eq!(b"hello world", &buf[..]);

let kind = stream.read(&mut buf).err().expect("expected error").kind();
assert!(kind == io::ErrorKind::WouldBlock || kind == io::ErrorKind::TimedOut);
let kind = stream.read_exact(&mut buf).err().expect("expected error").kind();
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut,
"unexpected_error: {:?}", kind);
}

// Ensure the `set_read_timeout` and `set_write_timeout` calls return errors
Expand Down