From 357bc562483dcf04c1f8d08bd1a831b144bf7d4c Mon Sep 17 00:00:00 2001 From: David Cook Date: Sat, 18 Feb 2023 18:40:05 -0600 Subject: [PATCH] Fix early-data test (#132) * Fix domain name in early-data test * Run early data test in CI * Add missing wake call * Workaround: write to OpenSSL's input This is necessary to work around an issue that only appears on Windows. * Don't rerun other tests in CI --- .github/workflows/CI.yml | 4 +++- tokio-rustls/tests/early-data.rs | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2e6541a..27a8ef5 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -45,7 +45,9 @@ jobs: toolchain: ${{ matrix.rust }} - name: Test - run: cargo test --all + run: | + cargo test --all + cargo test -p tokio-rustls --features early-data --test early-data lints: name: Lints diff --git a/tokio-rustls/tests/early-data.rs b/tokio-rustls/tests/early-data.rs index fe98290..5a6368b 100644 --- a/tokio-rustls/tests/early-data.rs +++ b/tokio-rustls/tests/early-data.rs @@ -9,6 +9,7 @@ use std::pin::Pin; use std::process::{Child, Command, Stdio}; use std::sync::Arc; use std::task::{Context, Poll}; +use std::thread; use std::time::Duration; use tokio::io::{split, AsyncRead, AsyncWriteExt, ReadBuf}; use tokio::net::TcpStream; @@ -34,6 +35,7 @@ impl Future for Read1 { if buf.filled().is_empty() { Poll::Ready(Ok(())) } else { + cx.waker().wake_by_ref(); Poll::Pending } } @@ -46,7 +48,7 @@ async fn send( ) -> io::Result> { let connector = TlsConnector::from(config).early_data(true); let stream = TcpStream::connect(&addr).await?; - let domain = rustls::ServerName::try_from("testserver.com").unwrap(); + let domain = rustls::ServerName::try_from("foobar.com").unwrap(); let stream = connector.connect(domain, stream).await?; let (mut rd, mut wd) = split(stream); @@ -140,6 +142,17 @@ async fn test_0rtt() -> io::Result<()> { let config = Arc::new(config); let addr = SocketAddr::from(([127, 0, 0, 1], 12354)); + // workaround: write to openssl s_server standard input periodically, to + // get it unstuck on Windows + let stdin = handle.0.stdin.take().unwrap(); + thread::spawn(move || { + let mut stdin = stdin; + loop { + thread::sleep(std::time::Duration::from_secs(5)); + std::io::Write::write_all(&mut stdin, b"\n").unwrap(); + } + }); + let io = send(config.clone(), addr, b"hello").await?; assert!(!io.get_ref().1.is_early_data_accepted());