Skip to content

Commit

Permalink
chore: add some extra testing with swapped client/server
Browse files Browse the repository at this point in the history
  • Loading branch information
mmastrac committed Nov 15, 2023
1 parent 9f2cdea commit d89ff0a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
18 changes: 11 additions & 7 deletions src/connection_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,17 @@ mod tests {
expect_write_1(&mut client).await;

// Half-close
client.into_inner().0.shutdown().await?;
let mut tcp = client.into_inner().0;
tcp.shutdown().await?;

// One byte will read fine
expect_read_1(&mut server).await;

// The next byte will return UnexpectedEof
expect_read_1_err(&mut server, ErrorKind::UnexpectedEof).await;

drop(tcp);

Ok(())
}

Expand Down Expand Up @@ -741,14 +744,15 @@ mod tests {
// One byte will read fine
expect_read_1(&mut server).await;

client
.into_inner()
.0
.write_all(b"THIS IS NOT A VALID TLS PACKET")
.await?;
let mut tcp = client.into_inner().0;
tcp.write_all(b"THIS IS NOT A VALID TLS PACKET").await?;

// The next byte will not
expect_read_1_err(&mut server, ErrorKind::InvalidData).await;

// Hold the TCP connection until here otherwise Windows/Mac may barf
drop(tcp);

Ok(())
}

Expand All @@ -773,7 +777,7 @@ mod tests {
// The next byte will not
expect_read_1_err(&mut server, ErrorKind::InvalidData).await;

// Hold the TCP connection until here otherwise Windows may barf
// Hold the TCP connection until here otherwise Windows/Mac may barf
drop(tcp);

Ok(())
Expand Down
56 changes: 48 additions & 8 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1731,12 +1731,24 @@ pub(super) mod tests {
Ok(())
}

#[rstest]
#[case(true)]
#[case(false)]
#[tokio::test]
async fn large_transfer_no_buffer_limit_or_handshake() -> TestResult {
async fn large_transfer_no_buffer_limit_or_handshake(
#[case] swap: bool,
) -> TestResult {
const BUF_SIZE: usize = 64 * 1024;
const BUF_COUNT: usize = 1024;

let (mut server, mut client) = tls_pair().await;
let (server, client) = tls_pair().await;

let (mut server, mut client) = if swap {
(client, server)
} else {
(server, client)
};

let a = spawn(async move {
// Heap allocate a large buffer and send it
let buf = vec![42; BUF_COUNT * BUF_SIZE];
Expand All @@ -1759,16 +1771,26 @@ pub(super) mod tests {
Ok(())
}

#[rstest]
#[case(true)]
#[case(false)]
#[tokio::test]
async fn large_transfer_with_buffer_limit() -> TestResult {
async fn large_transfer_with_buffer_limit(#[case] swap: bool) -> TestResult {
const BUF_SIZE: usize = 10 * 1024;
const BUF_COUNT: usize = 1024;

let (mut server, mut client) = tls_pair_handshake_buffer_size(
let (server, client) = tls_pair_handshake_buffer_size(
BUF_SIZE.try_into().ok(),
BUF_SIZE.try_into().ok(),
)
.await;

let (mut server, mut client) = if swap {
(client, server)
} else {
(server, client)
};

let a = spawn(async move {
// Heap allocate a large buffer and send it
let buf = vec![42; BUF_COUNT * BUF_SIZE];
Expand All @@ -1789,12 +1811,21 @@ pub(super) mod tests {
Ok(())
}

#[rstest]
#[case(true)]
#[case(false)]
#[tokio::test(flavor = "current_thread")]
async fn large_transfer_with_shutdown() -> TestResult {
async fn large_transfer_with_shutdown(#[case] swap: bool) -> TestResult {
const BUF_SIZE: usize = 10 * 1024;
const BUF_COUNT: usize = 1024;

let (mut server, mut client) = tls_pair_handshake().await;
let (server, client) = tls_pair_handshake().await;
let (mut server, mut client) = if swap {
(client, server)
} else {
(server, client)
};

let a = spawn(async move {
// Heap allocate a large buffer and send it
let buf = vec![42; BUF_COUNT * BUF_SIZE];
Expand All @@ -1815,13 +1846,22 @@ pub(super) mod tests {
Ok(())
}

#[rstest]
#[case(true)]
#[case(false)]
#[tokio::test(flavor = "current_thread")]
#[ntest::timeout(60000)]
async fn large_transfer_no_shutdown() -> TestResult {
async fn large_transfer_no_shutdown(#[case] swap: bool) -> TestResult {
const BUF_SIZE: usize = 10 * 1024;
const BUF_COUNT: usize = 1024;

let (mut server, mut client) = tls_pair_handshake().await;
let (server, client) = tls_pair_handshake().await;
let (mut server, mut client) = if swap {
(client, server)
} else {
(server, client)
};

let a = spawn(async move {
// Heap allocate a large buffer and send it
let buf = vec![42; BUF_COUNT * BUF_SIZE];
Expand Down

0 comments on commit d89ff0a

Please sign in to comment.