about summary refs log tree commit diff
path: root/src/libstd/net
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2017-01-13 10:42:30 +0100
committerGitHub <noreply@github.com>2017-01-13 10:42:30 +0100
commit629caf5a7e3a3bad70c82391e0bce077007f917f (patch)
treec3a286ef9b5880f0f8533d317ad880c0924b86b8 /src/libstd/net
parent97fb779429b8e11526d96758da56aec241304ad4 (diff)
parent30380137f87f1098c0ca6e33bafd9c78dd19c0a8 (diff)
downloadrust-629caf5a7e3a3bad70c82391e0bce077007f917f.tar.gz
rust-629caf5a7e3a3bad70c82391e0bce077007f917f.zip
Rollup merge of #38986 - APTy:fix-nonblocking-test, r=aturon
std/net/udp: Improve set_nonblocking test

While writing a separate change, I noticed the current test for `UdpSocket::set_nonblocking()` is fairly ineffective.

This fixes the test so that it validates that a correct error is returned on calls to `recv()` when no data is available.
Diffstat (limited to 'src/libstd/net')
-rw-r--r--src/libstd/net/udp.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs
index f8a5ec0b379..a9a19aee5d1 100644
--- a/src/libstd/net/udp.rs
+++ b/src/libstd/net/udp.rs
@@ -883,11 +883,23 @@ mod tests {
 
     #[test]
     fn set_nonblocking() {
-        let addr = next_test_ip4();
+        each_ip(&mut |addr, _| {
+            let socket = t!(UdpSocket::bind(&addr));
 
-        let stream = t!(UdpSocket::bind(&addr));
+            t!(socket.set_nonblocking(true));
+            t!(socket.set_nonblocking(false));
+
+            t!(socket.connect(addr));
 
-        t!(stream.set_nonblocking(true));
-        t!(stream.set_nonblocking(false));
+            t!(socket.set_nonblocking(false));
+            t!(socket.set_nonblocking(true));
+
+            let mut buf = [0];
+            match socket.recv(&mut buf) {
+                Ok(_) => panic!("expected error"),
+                Err(ref e) if e.kind() == ErrorKind::WouldBlock => {}
+                Err(e) => panic!("unexpected error {}", e),
+            }
+        })
     }
 }