Skip to content

Commit

Permalink
Fix some windows-specific issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Oct 4, 2023
1 parent e21f45a commit b4f606a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
18 changes: 10 additions & 8 deletions crates/test-programs/src/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<hyper::body::Incoming>,
Expand Down Expand Up @@ -34,20 +35,21 @@ impl Server {
F: Future<Output = Result<()>>,
{
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 {
Expand Down Expand Up @@ -92,8 +94,8 @@ impl Server {
})
}

pub fn addr(&self) -> &SocketAddr {
&self.addr
pub fn addr(&self) -> String {
format!("localhost:{}", self.addr.port())
}
}

Expand Down
6 changes: 1 addition & 5 deletions crates/test-programs/tests/wasi-http-components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
);
}

0 comments on commit b4f606a

Please sign in to comment.