1 |
From f107514aef0b25b0d959941df1e45b18a478151b Mon Sep 17 00:00:00 2001 |
2 |
From: Josh Stone <jistone@redhat.com> |
3 |
Date: Fri, 30 Nov 2018 15:33:40 -0800 |
4 |
Subject: [PATCH] Deal with EINTR in net timeout tests |
5 |
|
6 |
We've seen sporadic QE failures in the timeout tests on this assertion: |
7 |
|
8 |
assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut); |
9 |
|
10 |
So there's an error, but not either of the expected kinds. Adding a |
11 |
format to show the kind revealed `ErrorKind::Interrupted` (`EINTR`). |
12 |
|
13 |
For the cases that were using `read`, we can just use `read_exact` to |
14 |
keep trying after interruption. For those using `recv_from`, we have to |
15 |
manually loop until we get a non-interrupted result. |
16 |
--- |
17 |
src/libstd/net/tcp.rs | 10 ++++++---- |
18 |
src/libstd/net/udp.rs | 20 ++++++++++++++++---- |
19 |
src/libstd/sys/unix/ext/net.rs | 10 ++++++---- |
20 |
3 files changed, 28 insertions(+), 12 deletions(-) |
21 |
|
22 |
diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs |
23 |
index ad212a547579..be797803233a 100644 |
24 |
--- a/src/libstd/net/tcp.rs |
25 |
+++ b/src/libstd/net/tcp.rs |
26 |
@@ -1548,8 +1548,9 @@ mod tests { |
27 |
|
28 |
let mut buf = [0; 10]; |
29 |
let start = Instant::now(); |
30 |
- let kind = stream.read(&mut buf).err().expect("expected error").kind(); |
31 |
- assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut); |
32 |
+ let kind = stream.read_exact(&mut buf).err().expect("expected error").kind(); |
33 |
+ assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut, |
34 |
+ "unexpected_error: {:?}", kind); |
35 |
assert!(start.elapsed() > Duration::from_millis(400)); |
36 |
drop(listener); |
37 |
} |
38 |
@@ -1570,8 +1571,9 @@ mod tests { |
39 |
assert_eq!(b"hello world", &buf[..]); |
40 |
|
41 |
let start = Instant::now(); |
42 |
- let kind = stream.read(&mut buf).err().expect("expected error").kind(); |
43 |
- assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut); |
44 |
+ let kind = stream.read_exact(&mut buf).err().expect("expected error").kind(); |
45 |
+ assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut, |
46 |
+ "unexpected_error: {:?}", kind); |
47 |
assert!(start.elapsed() > Duration::from_millis(400)); |
48 |
drop(listener); |
49 |
} |
50 |
diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs |
51 |
index 0ebe3284b4f0..fc68abae05a0 100644 |
52 |
--- a/src/libstd/net/udp.rs |
53 |
+++ b/src/libstd/net/udp.rs |
54 |
@@ -1030,8 +1030,14 @@ mod tests { |
55 |
let mut buf = [0; 10]; |
56 |
|
57 |
let start = Instant::now(); |
58 |
- let kind = stream.recv_from(&mut buf).err().expect("expected error").kind(); |
59 |
- assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut); |
60 |
+ loop { |
61 |
+ let kind = stream.recv_from(&mut buf).err().expect("expected error").kind(); |
62 |
+ if kind != ErrorKind::Interrupted { |
63 |
+ assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut, |
64 |
+ "unexpected_error: {:?}", kind); |
65 |
+ break; |
66 |
+ } |
67 |
+ } |
68 |
assert!(start.elapsed() > Duration::from_millis(400)); |
69 |
} |
70 |
|
71 |
@@ -1049,8 +1055,14 @@ mod tests { |
72 |
assert_eq!(b"hello world", &buf[..]); |
73 |
|
74 |
let start = Instant::now(); |
75 |
- let kind = stream.recv_from(&mut buf).err().expect("expected error").kind(); |
76 |
- assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut); |
77 |
+ loop { |
78 |
+ let kind = stream.recv_from(&mut buf).err().expect("expected error").kind(); |
79 |
+ if kind != ErrorKind::Interrupted { |
80 |
+ assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut, |
81 |
+ "unexpected_error: {:?}", kind); |
82 |
+ break; |
83 |
+ } |
84 |
+ } |
85 |
assert!(start.elapsed() > Duration::from_millis(400)); |
86 |
} |
87 |
|
88 |
diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs |
89 |
index 55f43ccd7db4..737437c76b7c 100644 |
90 |
--- a/src/libstd/sys/unix/ext/net.rs |
91 |
+++ b/src/libstd/sys/unix/ext/net.rs |
92 |
@@ -1654,8 +1654,9 @@ mod test { |
93 |
or_panic!(stream.set_read_timeout(Some(Duration::from_millis(1000)))); |
94 |
|
95 |
let mut buf = [0; 10]; |
96 |
- let kind = stream.read(&mut buf).err().expect("expected error").kind(); |
97 |
- assert!(kind == io::ErrorKind::WouldBlock || kind == io::ErrorKind::TimedOut); |
98 |
+ let kind = stream.read_exact(&mut buf).err().expect("expected error").kind(); |
99 |
+ assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut, |
100 |
+ "unexpected_error: {:?}", kind); |
101 |
} |
102 |
|
103 |
#[test] |
104 |
@@ -1675,8 +1676,9 @@ mod test { |
105 |
or_panic!(stream.read(&mut buf)); |
106 |
assert_eq!(b"hello world", &buf[..]); |
107 |
|
108 |
- let kind = stream.read(&mut buf).err().expect("expected error").kind(); |
109 |
- assert!(kind == io::ErrorKind::WouldBlock || kind == io::ErrorKind::TimedOut); |
110 |
+ let kind = stream.read_exact(&mut buf).err().expect("expected error").kind(); |
111 |
+ assert!(kind == ErrorKind::WouldBlock || kind == ErrorKind::TimedOut, |
112 |
+ "unexpected_error: {:?}", kind); |
113 |
} |
114 |
|
115 |
// Ensure the `set_read_timeout` and `set_write_timeout` calls return errors |
116 |
-- |
117 |
2.19.1 |
118 |
|