Skip to content

Commit 2f987a1

Browse files
authored
log and quit on I/O error when echoing in wasi-http example (#1910)
Also, fix the relevant integration tests and ensure they run in CI. Signed-off-by: Joel Dice <[email protected]>
1 parent 2eeb917 commit 2f987a1

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ jobs:
115115
rust-cache: true
116116
nomad: true
117117

118-
- name: Cargo Unit Tests
118+
- name: Cargo Unit and Integration Tests
119119
run: |
120-
make test-unit
120+
make test-unit test-integration
121121
env:
122122
CARGO_INCREMENTAL: 0
123123

examples/wasi-http-rust-streaming-outgoing-body/spin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ version = "1.0.0"
77

88
[[component]]
99
id = "wasi-http-async"
10-
source = "target/wasm32-wasi/release/wasi_http_rust_async.wasm"
10+
source = "target/wasm32-wasi/release/wasi_http_rust_streaming_outgoing_body.wasm"
1111
[component.trigger]
1212
route = "/..."
1313
executor = { type = "wasi" }

examples/wasi-http-rust-streaming-outgoing-body/src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,18 @@ async fn handle_request(request: IncomingRequest, response_out: ResponseOutparam
6767
ResponseOutparam::set(response_out, Ok(response));
6868

6969
let mut stream = request.into_body_stream();
70-
while let Ok(Some(chunk)) = stream.try_next().await {
71-
if let Err(e) = body.send(chunk).await {
72-
eprintln!("Error sending body: {e}");
70+
while let Some(chunk) = stream.next().await {
71+
match chunk {
72+
Ok(chunk) => {
73+
if let Err(e) = body.send(chunk).await {
74+
eprintln!("Error sending body: {e}");
75+
break;
76+
}
77+
}
78+
Err(e) => {
79+
eprintln!("Error receiving body: {e}");
80+
break;
81+
}
7382
}
7483
}
7584
}

tests/integration.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -719,9 +719,12 @@ route = "/..."
719719
drop(future::select(server, rx).await);
720720
});
721721

722-
let controller =
723-
SpinTestController::with_manifest("examples/wasi-http-rust-async/spin.toml", &[], &[])
724-
.await?;
722+
let controller = SpinTestController::with_manifest(
723+
"examples/wasi-http-rust-streaming-outgoing-body/spin.toml",
724+
&[],
725+
&[],
726+
)
727+
.await?;
725728

726729
let mut request = Client::new().get(format!("http://{}/hash-all", controller.url));
727730
for path in bodies.keys() {
@@ -765,9 +768,12 @@ route = "/..."
765768
.collect::<Vec<_>>()
766769
};
767770

768-
let controller =
769-
SpinTestController::with_manifest("examples/wasi-http-rust-async/spin.toml", &[], &[])
770-
.await?;
771+
let controller = SpinTestController::with_manifest(
772+
"examples/wasi-http-rust-streaming-outgoing-body/spin.toml",
773+
&[],
774+
&[],
775+
)
776+
.await?;
771777

772778
let response = Client::new()
773779
.post(format!("http://{}/echo", controller.url))

0 commit comments

Comments
 (0)