Skip to content

Commit

Permalink
use larger buffers in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maminrayej committed Sep 2, 2023
1 parent b55690e commit cc16dfa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions tokio/tests/tcp_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions tokio/tests/uds_datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
Expand All @@ -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);

Expand Down
24 changes: 12 additions & 12 deletions tokio/tests/uds_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -75,15 +75,15 @@ 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());
assert_pending!(readable.poll());

// 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() {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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");
Expand All @@ -312,15 +312,15 @@ 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());
assert_pending!(readable.poll());

// 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() {
Expand All @@ -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;
}
Expand Down

0 comments on commit cc16dfa

Please sign in to comment.