1
1
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 ;
23
3
24
4
#[ test_log:: test]
25
5
fn http_server ( ) -> Result < ( ) > {
26
6
use std:: net:: TcpStream ;
27
7
use std:: thread:: sleep;
28
8
use std:: time:: Duration ;
29
9
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 ( ) ?;
33
19
34
20
// Clumsily wait for the server to accept connections.
35
21
' wait: loop {
36
22
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 ( ) {
38
24
break ' wait;
39
25
}
40
26
}
41
27
42
28
// Do some tests!
43
29
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 ( ) ?;
45
31
assert_eq ! ( body, "Hello, wasi:http/proxy world!\n " ) ;
46
32
47
- match ureq:: get ( "http://127.0.0.1:8080 /fail" ) . call ( ) {
33
+ match ureq:: get ( "http://127.0.0.1:8081 /fail" ) . call ( ) {
48
34
Ok ( body) => {
49
35
unreachable ! ( "unexpected success from /fail: {:?}" , body) ;
50
36
}
@@ -56,7 +42,7 @@ fn http_server() -> Result<()> {
56
42
57
43
const MESSAGE : & [ u8 ] = b"hello, echoserver!\n " ;
58
44
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" )
60
46
. send ( MESSAGE ) ?
61
47
. into_string ( ) ?;
62
48
assert_eq ! ( body. as_bytes( ) , MESSAGE ) ;
@@ -70,7 +56,7 @@ fn http_server() -> Result<()> {
70
56
( "Purple" , "Beets" ) ,
71
57
] ;
72
58
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" ) ;
74
60
for ( name, value) in test_headers {
75
61
response = response. set ( name, value) ;
76
62
}
@@ -81,9 +67,7 @@ fn http_server() -> Result<()> {
81
67
assert_eq ! ( response. header( name) , Some ( value) ) ;
82
68
}
83
69
84
- if wasmtime_thread. is_finished ( ) {
85
- wasmtime_thread. join ( ) . expect ( "wasmtime panicked" ) ?;
86
- }
70
+ wasmtime_process. kill ( ) ?;
87
71
88
72
Ok ( ( ) )
89
73
}
0 commit comments