std: Fix a flaky test on OSX 10.10

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 
This commit is contained in:
Alex Crichton 2014-11-15 11:23:40 -08:00
parent 1e4e55aebc
commit 3e0368e621

@ -661,23 +661,22 @@ mod test {
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 @@ mod test {
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);
}
}
}