From d89ff0ab272d3ce8da27c588c7a04dd50378772e Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Tue, 14 Nov 2023 21:11:41 -0700 Subject: [PATCH] chore: add some extra testing with swapped client/server --- src/connection_stream.rs | 18 ++++++++----- src/stream.rs | 56 ++++++++++++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 15 deletions(-) diff --git a/src/connection_stream.rs b/src/connection_stream.rs index 7200fca..3cc3899 100644 --- a/src/connection_stream.rs +++ b/src/connection_stream.rs @@ -647,7 +647,8 @@ 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; @@ -655,6 +656,8 @@ mod tests { // The next byte will return UnexpectedEof expect_read_1_err(&mut server, ErrorKind::UnexpectedEof).await; + drop(tcp); + Ok(()) } @@ -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(()) } @@ -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(()) diff --git a/src/stream.rs b/src/stream.rs index 08b4f97..d4804b5 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -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]; @@ -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]; @@ -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]; @@ -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];