Skip to content

Commit

Permalink
Fix spurious failures (tokio-rs#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
carllerche authored Apr 25, 2018
1 parent a4f3f0d commit 4c261de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
30 changes: 14 additions & 16 deletions src/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ use std::net::{self, Ipv4Addr, Ipv6Addr, SocketAddr};
///
/// // This operation will fail if the address is in use, so we select different ports for each
/// // socket.
/// let sender_socket = UdpSocket::bind(&"127.0.0.1:7777".parse()?)?;
/// let echoer_socket = UdpSocket::bind(&"127.0.0.1:11100".parse()?)?;
/// let sender_socket = UdpSocket::bind(&"127.0.0.1:0".parse()?)?;
/// let echoer_socket = UdpSocket::bind(&"127.0.0.1:0".parse()?)?;
///
/// // If we do not use connect here, SENDER and ECHOER would need to call send_to and recv_from
/// // respectively.
/// sender_socket.connect("127.0.0.1:11100".parse()?)?;
/// sender_socket.connect(echoer_socket.local_addr().unwrap())?;
///
/// // We need a Poll to check if SENDER is ready to be written into, and if ECHOER is ready to be
/// // read from.
Expand Down Expand Up @@ -103,7 +103,7 @@ impl UdpSocket {
/// use mio::net::UdpSocket;
///
/// // We must bind it to an open address.
/// let socket = match UdpSocket::bind(&"127.0.0.1:7777".parse()?) {
/// let socket = match UdpSocket::bind(&"127.0.0.1:0".parse()?) {
/// Ok(new_socket) => new_socket,
/// Err(fail) => {
/// // We panic! here, but you could try to bind it again on another address.
Expand Down Expand Up @@ -155,10 +155,8 @@ impl UdpSocket {
/// # fn try_main() -> Result<(), Box<Error>> {
/// use mio::net::UdpSocket;
///
/// let addr = "127.0.0.1:7777".parse()?;
/// let addr = "127.0.0.1:0".parse()?;
/// let socket = UdpSocket::bind(&addr)?;
///
/// assert_eq!(socket.local_addr()?, addr);
/// # Ok(())
/// # }
/// #
Expand All @@ -185,7 +183,7 @@ impl UdpSocket {
/// use mio::net::UdpSocket;
///
/// // We must bind it to an open address.
/// let socket = UdpSocket::bind(&"127.0.0.1:7777".parse()?)?;
/// let socket = UdpSocket::bind(&"127.0.0.1:0".parse()?)?;
/// let cloned_socket = socket.try_clone()?;
///
/// assert_eq!(socket.local_addr()?, cloned_socket.local_addr()?);
Expand Down Expand Up @@ -219,8 +217,8 @@ impl UdpSocket {
/// # use std::error::Error;
/// # fn try_main() -> Result<(), Box<Error>> {
/// use mio::net::UdpSocket;
///
/// let socket = UdpSocket::bind(&"127.0.0.1:7777".parse()?)?;
///
/// let socket = UdpSocket::bind(&"127.0.0.1:0".parse()?)?;
///
/// // We must check if the socket is writable before calling send_to,
/// // or we could run into a WouldBlock error.
Expand Down Expand Up @@ -250,7 +248,7 @@ impl UdpSocket {
/// # fn try_main() -> Result<(), Box<Error>> {
/// use mio::net::UdpSocket;
///
/// let socket = UdpSocket::bind(&"127.0.0.1:11100".parse()?)?;
/// let socket = UdpSocket::bind(&"127.0.0.1:0".parse()?)?;
///
/// // We must check if the socket is readable before calling recv_from,
/// // or we could run into a WouldBlock error.
Expand Down Expand Up @@ -302,11 +300,11 @@ impl UdpSocket {
/// # fn try_main() -> Result<(), Box<Error>> {
/// use mio::net::UdpSocket;
///
/// let broadcast_socket = UdpSocket::bind(&"127.0.0.1:7777".parse()?)?;
/// let broadcast_socket = UdpSocket::bind(&"127.0.0.1:0".parse()?)?;
/// if broadcast_socket.broadcast()? == false {
/// broadcast_socket.set_broadcast(true)?;
/// }
///
///
/// assert_eq!(broadcast_socket.broadcast()?, true);
/// #
/// # Ok(())
Expand Down Expand Up @@ -335,7 +333,7 @@ impl UdpSocket {
/// # fn try_main() -> Result<(), Box<Error>> {
/// use mio::net::UdpSocket;
///
/// let broadcast_socket = UdpSocket::bind(&"127.0.0.1:7777".parse()?)?;
/// let broadcast_socket = UdpSocket::bind(&"127.0.0.1:0".parse()?)?;
/// assert_eq!(broadcast_socket.broadcast()?, false);
/// #
/// # Ok(())
Expand Down Expand Up @@ -419,7 +417,7 @@ impl UdpSocket {
/// # fn try_main() -> Result<(), Box<Error>> {
/// use mio::net::UdpSocket;
///
/// let socket = UdpSocket::bind(&"127.0.0.1:7777".parse()?)?;
/// let socket = UdpSocket::bind(&"127.0.0.1:0".parse()?)?;
/// if socket.ttl()? < 255 {
/// socket.set_ttl(255)?;
/// }
Expand Down Expand Up @@ -451,7 +449,7 @@ impl UdpSocket {
/// # fn try_main() -> Result<(), Box<Error>> {
/// use mio::net::UdpSocket;
///
/// let socket = UdpSocket::bind(&"127.0.0.1:7777".parse()?)?;
/// let socket = UdpSocket::bind(&"127.0.0.1:0".parse()?)?;
/// socket.set_ttl(255)?;
///
/// assert_eq!(socket.ttl()?, 255);
Expand Down
9 changes: 1 addition & 8 deletions test/test_custom_evented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,13 @@ mod stress {
}));
}

let per_thread: Vec<_> = threads.into_iter()
let _: Vec<_> = threads.into_iter()
.map(|th| th.join().unwrap())
.collect();

for entry in entries.iter() {
assert_eq!(PER_ENTRY, entry.num.load(Relaxed));
}

for th in per_thread {
// Kind of annoying that we can't really test anything better than this,
// but CI tends to be very non deterministic when it comes to multi
// threading.
assert!(th > 0, "actual={:?}", th);
}
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions test/test_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ fn connect_error() {
},
Err(e) => panic!("TcpStream::connect unexpected error {:?}", e)
};

poll.register(&l, Token(0), Ready::writable(), PollOpt::edge()).unwrap();

'outer:
Expand Down

0 comments on commit 4c261de

Please sign in to comment.