From 1134cbb168db0b562d757cfb496957b20b8c5378 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Sat, 14 Oct 2023 17:09:07 +0200 Subject: [PATCH] net: fix flaky doctest for `TcpStream::into_std` (#6074) --- tokio/src/net/tcp/stream.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 707f73d41d0..0a173a3d8b5 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -222,10 +222,14 @@ impl TcpStream { /// #[tokio::main] /// async fn main() -> Result<(), Box> { /// let mut data = [0u8; 12]; + /// # if false { /// let listener = TcpListener::bind("127.0.0.1:34254").await?; - /// # let handle = tokio::spawn(async { - /// # let mut stream: TcpStream = TcpStream::connect("127.0.0.1:34254").await.unwrap(); - /// # stream.write(b"Hello world!").await.unwrap(); + /// # } + /// # let listener = TcpListener::bind("127.0.0.1:0").await?; + /// # let addr = listener.local_addr().unwrap(); + /// # let handle = tokio::spawn(async move { + /// # let mut stream: TcpStream = TcpStream::connect(addr).await.unwrap(); + /// # stream.write_all(b"Hello world!").await.unwrap(); /// # }); /// let (tokio_tcp_stream, _) = listener.accept().await?; /// let mut std_tcp_stream = tokio_tcp_stream.into_std()?;