]> git.lizzy.rs Git - rust.git/commitdiff
std: Fix a flaky test on OSX 10.10
authorAlex Crichton <alex@alexcrichton.com>
Sat, 15 Nov 2014 19:23:40 +0000 (11:23 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Sat, 15 Nov 2014 19:23:40 +0000 (11:23 -0800)
This test was somewhat sketchy already with a `loop` around `write`, so this
just adds some explicit synchronization to only call `write` once and guarantee
that the error happens.

Closes #18900

src/libstd/io/net/tcp.rs

index 2545e07cbb5c2bd1dddbbe5a3697502abeb1ffdd..24fc2998ee696f49766abf41327ed3bf9a9d6b7d 100644 (file)
@@ -661,23 +661,22 @@ fn write_close_ip4() {
         let addr = next_test_ip4();
         let mut acceptor = TcpListener::bind(addr).listen();
 
+        let (tx, rx) = channel();
         spawn(proc() {
-            let _stream = TcpStream::connect(addr);
-            // Close
+            drop(TcpStream::connect(addr));
+            tx.send(());
         });
 
         let mut stream = acceptor.accept();
+        rx.recv();
         let buf = [0];
-        loop {
-            match stream.write(buf) {
-                Ok(..) => {}
-                Err(e) => {
-                    assert!(e.kind == ConnectionReset ||
-                            e.kind == BrokenPipe ||
-                            e.kind == ConnectionAborted,
-                            "unknown error: {}", e);
-                    break;
-                }
+        match stream.write(buf) {
+            Ok(..) => {}
+            Err(e) => {
+                assert!(e.kind == ConnectionReset ||
+                        e.kind == BrokenPipe ||
+                        e.kind == ConnectionAborted,
+                        "unknown error: {}", e);
             }
         }
     }
@@ -687,23 +686,22 @@ fn write_close_ip6() {
         let addr = next_test_ip6();
         let mut acceptor = TcpListener::bind(addr).listen();
 
+        let (tx, rx) = channel();
         spawn(proc() {
-            let _stream = TcpStream::connect(addr);
-            // Close
+            drop(TcpStream::connect(addr));
+            tx.send(());
         });
 
         let mut stream = acceptor.accept();
+        rx.recv();
         let buf = [0];
-        loop {
-            match stream.write(buf) {
-                Ok(..) => {}
-                Err(e) => {
-                    assert!(e.kind == ConnectionReset ||
-                            e.kind == BrokenPipe ||
-                            e.kind == ConnectionAborted,
-                            "unknown error: {}", e);
-                    break;
-                }
+        match stream.write(buf) {
+            Ok(..) => {}
+            Err(e) => {
+                assert!(e.kind == ConnectionReset ||
+                        e.kind == BrokenPipe ||
+                        e.kind == ConnectionAborted,
+                        "unknown error: {}", e);
             }
         }
     }