Skip to content

Commit

Permalink
Fix early-data test (hyperium#132)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
divergentdave authored Feb 19, 2023
1 parent e3841d6 commit 357bc56
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion tokio-rustls/tests/early-data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +35,7 @@ impl<T: AsyncRead + Unpin> Future for Read1<T> {
if buf.filled().is_empty() {
Poll::Ready(Ok(()))
} else {
cx.waker().wake_by_ref();
Poll::Pending
}
}
Expand All @@ -46,7 +48,7 @@ async fn send(
) -> io::Result<TlsStream<TcpStream>> {
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);
Expand Down Expand Up @@ -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());

Expand Down

0 comments on commit 357bc56

Please sign in to comment.