From cc16dfaa8d3ed800fe51ff635b74c97192a7ce34 Mon Sep 17 00:00:00 2001 From: "M.Amin Rayej" Date: Sun, 3 Sep 2023 01:55:54 +0330 Subject: [PATCH] use larger buffers in tests --- tokio/tests/tcp_stream.rs | 6 +++--- tokio/tests/uds_datagram.rs | 6 +++--- tokio/tests/uds_stream.rs | 24 ++++++++++++------------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tokio/tests/tcp_stream.rs b/tokio/tests/tcp_stream.rs index 725a60169ea..e62aace03bd 100644 --- a/tokio/tests/tcp_stream.rs +++ b/tokio/tests/tcp_stream.rs @@ -30,7 +30,7 @@ async fn set_linger() { #[tokio::test] async fn try_read_write() { - const DATA: &[u8] = b"this is some data to write to the socket"; + const DATA: &[u8] = &[0u8; 30000]; // Create listener let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); @@ -96,7 +96,7 @@ async fn try_read_write() { client.writable().await.unwrap(); // Fill the write buffer using vectored I/O - let data_bufs: Vec<_> = DATA.chunks(10).map(io::IoSlice::new).collect(); + let data_bufs: Vec<_> = DATA.chunks(30).map(io::IoSlice::new).collect(); loop { // Still ready let mut writable = task::spawn(client.writable()); @@ -286,7 +286,7 @@ fn write_until_pending(stream: &mut TcpStream) -> usize { #[tokio::test] async fn try_read_buf() { - const DATA: &[u8] = b"this is some data to write to the socket"; + const DATA: &[u8] = &[0u8; 30000]; // Create listener let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); diff --git a/tokio/tests/uds_datagram.rs b/tokio/tests/uds_datagram.rs index ba3c13a79c4..5d7e7ddd81d 100644 --- a/tokio/tests/uds_datagram.rs +++ b/tokio/tests/uds_datagram.rs @@ -414,7 +414,7 @@ async fn poll_ready() -> io::Result<()> { #[tokio::test(flavor = "current_thread")] async fn coop_uds() -> io::Result<()> { - use std::sync::atomic::{AtomicU64, Ordering}; + use std::sync::atomic::{AtomicU32, Ordering}; use std::time::{Duration, Instant}; const HELLO: &[u8] = b"hello world"; @@ -426,7 +426,7 @@ async fn coop_uds() -> io::Result<()> { let client = std::os::unix::net::UnixDatagram::unbound().unwrap(); let server = UnixDatagram::bind(&server_path).unwrap(); - let counter = Arc::new(AtomicU64::new(0)); + let counter = Arc::new(AtomicU32::new(0)); let counter_jh = tokio::spawn({ let counter = counter.clone(); @@ -449,7 +449,7 @@ async fn coop_uds() -> io::Result<()> { counter_jh.abort(); let _ = counter_jh.await; - let expected = ((DURATION.as_secs() * 4) as f64 * 0.5) as u64; + let expected = ((DURATION.as_secs() * 4) as f64 * 0.5) as u32; let counter = counter.load(Ordering::Relaxed); assert!(counter >= expected); diff --git a/tokio/tests/uds_stream.rs b/tokio/tests/uds_stream.rs index b8c4e6a8eed..b8513a6dde1 100644 --- a/tokio/tests/uds_stream.rs +++ b/tokio/tests/uds_stream.rs @@ -63,7 +63,7 @@ async fn shutdown() -> std::io::Result<()> { #[tokio::test] async fn try_read_write() -> std::io::Result<()> { - let msg = b"hello world"; + const DATA: &[u8] = &[0u8; 30000]; let dir = tempfile::tempdir()?; let bind_path = dir.path().join("bind.sock"); @@ -75,7 +75,7 @@ async fn try_read_write() -> std::io::Result<()> { let client = UnixStream::connect(&bind_path).await?; let (server, _) = listener.accept().await?; - let mut written = msg.to_vec(); + let mut written = DATA.to_vec(); // Track the server receiving data let mut readable = task::spawn(server.readable()); @@ -83,7 +83,7 @@ async fn try_read_write() -> std::io::Result<()> { // Write data. client.writable().await?; - assert_eq!(msg.len(), client.try_write(msg)?); + assert_eq!(DATA.len(), client.try_write(DATA)?); // The task should be notified while !readable.is_woken() { @@ -96,8 +96,8 @@ async fn try_read_write() -> std::io::Result<()> { let mut writable = task::spawn(client.writable()); assert_ready_ok!(writable.poll()); - match client.try_write(msg) { - Ok(n) => written.extend(&msg[..n]), + match client.try_write(DATA) { + Ok(n) => written.extend(&DATA[..n]), Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => { break; } @@ -131,14 +131,14 @@ async fn try_read_write() -> std::io::Result<()> { client.writable().await.unwrap(); // Fill the write buffer using vectored I/O - let msg_bufs: Vec<_> = msg.chunks(3).map(io::IoSlice::new).collect(); + let msg_bufs: Vec<_> = DATA.chunks(30).map(io::IoSlice::new).collect(); loop { // Still ready let mut writable = task::spawn(client.writable()); assert_ready_ok!(writable.poll()); match client.try_write_vectored(&msg_bufs) { - Ok(n) => written.extend(&msg[..n]), + Ok(n) => written.extend(&DATA[..n]), Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => { break; } @@ -300,7 +300,7 @@ fn write_until_pending(stream: &mut UnixStream) { #[tokio::test] async fn try_read_buf() -> std::io::Result<()> { - let msg = b"hello world"; + const DATA: &[u8] = &[0u8; 30000]; let dir = tempfile::tempdir()?; let bind_path = dir.path().join("bind.sock"); @@ -312,7 +312,7 @@ async fn try_read_buf() -> std::io::Result<()> { let client = UnixStream::connect(&bind_path).await?; let (server, _) = listener.accept().await?; - let mut written = msg.to_vec(); + let mut written = DATA.to_vec(); // Track the server receiving data let mut readable = task::spawn(server.readable()); @@ -320,7 +320,7 @@ async fn try_read_buf() -> std::io::Result<()> { // Write data. client.writable().await?; - assert_eq!(msg.len(), client.try_write(msg)?); + assert_eq!(DATA.len(), client.try_write(DATA)?); // The task should be notified while !readable.is_woken() { @@ -333,8 +333,8 @@ async fn try_read_buf() -> std::io::Result<()> { let mut writable = task::spawn(client.writable()); assert_ready_ok!(writable.poll()); - match client.try_write(msg) { - Ok(n) => written.extend(&msg[..n]), + match client.try_write(DATA) { + Ok(n) => written.extend(&DATA[..n]), Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => { break; }