From b4f606af1438e507d55a6ba90a3d2c67692e7d9c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 4 Oct 2023 09:09:25 -0700 Subject: [PATCH] Fix some windows-specific issues --- crates/test-programs/src/http_server.rs | 18 ++++++++++-------- .../tests/wasi-http-components.rs | 6 +----- .../bin/outbound_request_invalid_dnsname.rs | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/crates/test-programs/src/http_server.rs b/crates/test-programs/src/http_server.rs index 8422c1026036..a3c7efb63c62 100644 --- a/crates/test-programs/src/http_server.rs +++ b/crates/test-programs/src/http_server.rs @@ -3,9 +3,10 @@ use http_body_util::{combinators::BoxBody, BodyExt, Full}; use hyper::{body::Bytes, service::service_fn, Request, Response}; use std::{ future::Future, - net::{SocketAddr, TcpListener, TcpStream}, + net::{SocketAddr, TcpStream}, thread::JoinHandle, }; +use tokio::net::TcpListener; async fn test( mut req: Request, @@ -34,20 +35,21 @@ impl Server { F: Future>, { let addr = SocketAddr::from(([127, 0, 0, 1], 0)); - let listener = TcpListener::bind(addr).context("failed to bind")?; - let addr = listener.local_addr().context("failed to get local addr")?; let rt = tokio::runtime::Builder::new_current_thread() .enable_all() .build() .context("failed to start tokio runtime")?; + + let listener = + rt.block_on(async move { TcpListener::bind(addr).await.context("failed to bind") })?; + let addr = listener.local_addr().context("failed to get local addr")?; let worker = std::thread::spawn(move || { tracing::debug!("dedicated thread to start listening"); rt.block_on(async move { tracing::debug!("preparing to accept connection"); - let (stream, _) = listener.accept().map_err(anyhow::Error::from)?; - let io = tokio::net::TcpStream::from_std(stream).map_err(anyhow::Error::from)?; - run(io).await + let (stream, _) = listener.accept().await.map_err(anyhow::Error::from)?; + run(stream).await }) }); Ok(Self { @@ -92,8 +94,8 @@ impl Server { }) } - pub fn addr(&self) -> &SocketAddr { - &self.addr + pub fn addr(&self) -> String { + format!("localhost:{}", self.addr.port()) } } diff --git a/crates/test-programs/tests/wasi-http-components.rs b/crates/test-programs/tests/wasi-http-components.rs index 2756407751f3..7d70cb365036 100644 --- a/crates/test-programs/tests/wasi-http-components.rs +++ b/crates/test-programs/tests/wasi-http-components.rs @@ -82,7 +82,7 @@ async fn run(name: &str, server: &Server) -> Result<()> { for (var, val) in test_programs::wasi_tests_environment() { builder.env(var, val); } - builder.env("HTTP_SERVER", &server.addr().to_string()); + builder.env("HTTP_SERVER", server.addr()); let wasi = builder.build(); let http = WasiHttpCtx; @@ -109,10 +109,6 @@ async fn run(name: &str, server: &Server) -> Result<()> { } #[test_log::test(tokio::test(flavor = "multi_thread"))] -#[cfg_attr( - windows, - ignore = "test is currently flaky in ci and needs to be debugged" -)] async fn outbound_request_get() -> Result<()> { let server = Server::http1()?; run("outbound_request_get", &server).await diff --git a/crates/test-programs/wasi-http-tests/src/bin/outbound_request_invalid_dnsname.rs b/crates/test-programs/wasi-http-tests/src/bin/outbound_request_invalid_dnsname.rs index 9fef3bfdca25..a36e5384336e 100644 --- a/crates/test-programs/wasi-http-tests/src/bin/outbound_request_invalid_dnsname.rs +++ b/crates/test-programs/wasi-http-tests/src/bin/outbound_request_invalid_dnsname.rs @@ -12,7 +12,7 @@ fn main() { let error = res.unwrap_err().to_string(); assert!( - error.starts_with("Error::InvalidUrl(\"failed to lookup address information:"), + error.starts_with("Error::InvalidUrl(\""), "bad error: {error}" ); }