Skip to content

Commit a8358de

Browse files
committed
Spawn the wasmtime executable rather than using wasmtime_cli.
1 parent 5a756c8 commit a8358de

File tree

3 files changed

+16
-36
lines changed

3 files changed

+16
-36
lines changed

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ authors = [
4949
[workspace.dependencies]
5050
anyhow = "1"
5151
cargo_metadata = "0.18.1"
52-
clap = { version = "4.5.23", features = ["derive"] }
5352
futures-core = "0.3.19"
5453
futures-lite = "1.12.0"
5554
heck = "0.5"
@@ -66,7 +65,6 @@ test-programs-artifacts = { path = "test-programs/artifacts" }
6665
ureq = { version = "2.12.1", default-features = false }
6766
wasi = "0.14.0"
6867
wasmtime = "26"
69-
wasmtime-cli = "26"
7068
wasmtime-wasi = "26"
7169
wasmtime-wasi-http = "26"
7270
wstd = { path = "." }

test-programs/artifacts/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ publish = false
99

1010
[dev-dependencies]
1111
anyhow.workspace = true
12-
clap.workspace = true
1312
test-log.workspace = true
1413
test-programs-artifacts.workspace = true
1514
ureq.workspace = true
1615
wasmtime.workspace = true
17-
wasmtime-cli.workspace = true
1816
wasmtime-wasi.workspace = true
1917
wasmtime-wasi-http.workspace = true
2018

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,36 @@
11
use anyhow::Result;
2-
3-
fn run_in_wasmtime(wasm: &str) -> Result<()> {
4-
use clap::Parser;
5-
use wasmtime_cli::commands::ServeCommand;
6-
7-
// Run wasmtime serve.
8-
// Enable -Scli because we build with the default adapter rather than the
9-
// proxy adapter.
10-
// Disable logging so that Wasmtime's tracing_subscriber registration
11-
// doesn't conflict with the test harness' registration.
12-
let serve =
13-
match ServeCommand::try_parse_from(["serve", "-Scli", "-Dlogging=n", wasm].into_iter()) {
14-
Ok(serve) => serve,
15-
Err(e) => {
16-
dbg!(&e);
17-
return Err(e.into());
18-
}
19-
};
20-
21-
serve.execute()
22-
}
2+
use std::process::Command;
233

244
#[test_log::test]
255
fn http_server() -> Result<()> {
266
use std::net::TcpStream;
277
use std::thread::sleep;
288
use std::time::Duration;
299

30-
// Start a `wasmtime serve` server.
31-
let wasmtime_thread =
32-
std::thread::spawn(move || run_in_wasmtime(test_programs_artifacts::HTTP_SERVER));
10+
// Run wasmtime serve.
11+
// Enable -Scli because we currently don't have a way to build with the
12+
// proxy adapter, so we build with the default adapter.
13+
let mut wasmtime_process = Command::new("wasmtime")
14+
.arg("serve")
15+
.arg("-Scli")
16+
.arg("--addr=127.0.0.1:8081")
17+
.arg(test_programs_artifacts::HTTP_SERVER)
18+
.spawn()?;
3319

3420
// Clumsily wait for the server to accept connections.
3521
'wait: loop {
3622
sleep(Duration::from_millis(100));
37-
if TcpStream::connect("127.0.0.1:8080").is_ok() {
23+
if TcpStream::connect("127.0.0.1:8081").is_ok() {
3824
break 'wait;
3925
}
4026
}
4127

4228
// Do some tests!
4329

44-
let body: String = ureq::get("http://127.0.0.1:8080").call()?.into_string()?;
30+
let body: String = ureq::get("http://127.0.0.1:8081").call()?.into_string()?;
4531
assert_eq!(body, "Hello, wasi:http/proxy world!\n");
4632

47-
match ureq::get("http://127.0.0.1:8080/fail").call() {
33+
match ureq::get("http://127.0.0.1:8081/fail").call() {
4834
Ok(body) => {
4935
unreachable!("unexpected success from /fail: {:?}", body);
5036
}
@@ -56,7 +42,7 @@ fn http_server() -> Result<()> {
5642

5743
const MESSAGE: &[u8] = b"hello, echoserver!\n";
5844

59-
let body: String = ureq::get("http://127.0.0.1:8080/echo")
45+
let body: String = ureq::get("http://127.0.0.1:8081/echo")
6046
.send(MESSAGE)?
6147
.into_string()?;
6248
assert_eq!(body.as_bytes(), MESSAGE);
@@ -70,7 +56,7 @@ fn http_server() -> Result<()> {
7056
("Purple", "Beets"),
7157
];
7258

73-
let mut response = ureq::get("http://127.0.0.1:8080/echo-headers");
59+
let mut response = ureq::get("http://127.0.0.1:8081/echo-headers");
7460
for (name, value) in test_headers {
7561
response = response.set(name, value);
7662
}
@@ -81,9 +67,7 @@ fn http_server() -> Result<()> {
8167
assert_eq!(response.header(name), Some(value));
8268
}
8369

84-
if wasmtime_thread.is_finished() {
85-
wasmtime_thread.join().expect("wasmtime panicked")?;
86-
}
70+
wasmtime_process.kill()?;
8771

8872
Ok(())
8973
}

0 commit comments

Comments
 (0)