Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit beed238

Browse files
alexcrichtonrvolosatovs
authored andcommitted
Update tests with new wit-bindgen APIs
1 parent 418d792 commit beed238

4 files changed

Lines changed: 22 additions & 31 deletions

File tree

crates/test-programs/src/bin/api_0_3_proxy.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use futures::{join, SinkExt as _};
1+
use futures::join;
22
use test_programs::p3::wasi::http::types::{ErrorCode, Headers, Request, Response};
33
use test_programs::p3::{wit_future, wit_stream};
44
use wit_bindgen_rt::async_support::spawn;
@@ -39,10 +39,8 @@ impl test_programs::p3::proxy::exports::wasi::http::handler::Guest for T {
3939
spawn(async {
4040
join!(
4141
async {
42-
contents_tx
43-
.send(b"hello, world!".to_vec())
44-
.await
45-
.expect("writing response");
42+
let remaining = contents_tx.write_all(b"hello, world!".to_vec()).await;
43+
assert!(remaining.is_empty());
4644
drop(contents_tx);
4745
trailers_tx.write(Ok(None));
4846
},
@@ -51,7 +49,6 @@ impl test_programs::p3::proxy::exports::wasi::http::handler::Guest for T {
5149
.await
5250
.expect("failed to transmit response")
5351
.unwrap()
54-
.unwrap()
5552
}
5653
);
5754
});

crates/test-programs/src/bin/http_0_3_outbound_request_content_length.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use futures::SinkExt as _;
21
use test_programs::p3::wasi::http::types::{ErrorCode, Headers, Method, Request, Scheme, Trailers};
32
use test_programs::p3::{wit_future, wit_stream};
43
use wit_bindgen_rt::async_support::{FutureWriter, StreamWriter};
@@ -44,17 +43,19 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
4443
{
4544
println!("writing enough");
4645
let (_, mut contents_tx, trailers_tx) = make_request();
47-
contents_tx.send(b"long enough".to_vec()).await.unwrap();
46+
let remaining = contents_tx.write_all(b"long enough".to_vec()).await;
47+
assert!(remaining.is_empty());
4848
drop(contents_tx);
49-
trailers_tx.write(Ok(None)).await;
49+
trailers_tx.write(Ok(None)).await.unwrap();
5050
}
5151

5252
{
5353
println!("writing too little");
5454
let (_, mut contents_tx, trailers_tx) = make_request();
55-
contents_tx.send(b"msg".to_vec()).await.unwrap();
55+
let remaining = contents_tx.write_all(b"msg".to_vec()).await;
56+
assert!(remaining.is_empty());
5657
drop(contents_tx);
57-
trailers_tx.write(Ok(None)).await;
58+
trailers_tx.write(Ok(None)).await.unwrap();
5859

5960
// handle()
6061

@@ -71,12 +72,10 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
7172
{
7273
println!("writing too much");
7374
let (_, mut contents_tx, trailers_tx) = make_request();
74-
contents_tx
75-
.send(b"more than 11 bytes".to_vec())
76-
.await
77-
.unwrap();
75+
let remaining = contents_tx.write_all(b"more than 11 bytes".to_vec()).await;
76+
assert!(remaining.is_empty());
7877
drop(contents_tx);
79-
trailers_tx.write(Ok(None)).await;
78+
trailers_tx.write(Ok(None)).await.unwrap();
8079

8180
// TODO: Figure out how/if to represent this in wasip3
8281
//let e = request_body

crates/test-programs/src/bin/http_0_3_outbound_request_response_build.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use futures::SinkExt as _;
21
use test_programs::p3::wasi::http::types::{Fields, Headers, Method, Request, Response, Scheme};
32
use test_programs::p3::{wit_future, wit_stream};
43

@@ -26,7 +25,8 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
2625
request
2726
.set_authority(Some("www.example.com"))
2827
.expect("setting authority");
29-
contents_tx.send(b"request-body".to_vec()).await.unwrap();
28+
let remaining = contents_tx.write_all(b"request-body".to_vec()).await;
29+
assert!(remaining.is_empty());
3030
}
3131
{
3232
let headers = Headers::from_list(&[(
@@ -37,7 +37,8 @@ impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
3737
let (mut contents_tx, contents_rx) = wit_stream::new();
3838
let (_, trailers_rx) = wit_future::new();
3939
let _ = Response::new(headers, Some(contents_rx), trailers_rx);
40-
contents_tx.send(b"response-body".to_vec()).await.unwrap();
40+
let remaining = contents_tx.write_all(b"response-body".to_vec()).await;
41+
assert!(remaining.is_empty());
4142
}
4243

4344
{

crates/test-programs/src/p3/http.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use core::fmt;
2-
31
use anyhow::{anyhow, Context as _, Result};
4-
use futures::{try_join, SinkExt as _, TryStreamExt as _};
2+
use core::fmt;
3+
use futures::try_join;
54

65
use crate::p3::wasi::http::{handler, types};
76
use crate::p3::{wit_future, wit_stream};
@@ -92,20 +91,17 @@ pub async fn request(
9291
let ((), (), response) = try_join!(
9392
async {
9493
if let Some(buf) = body {
95-
contents_tx
96-
.send(buf.into())
97-
.await
98-
.expect("failed to send body content chunk");
94+
let remaining = contents_tx.write_all(buf.into()).await;
95+
assert!(remaining.is_empty());
9996
}
10097
drop(contents_tx);
101-
trailers_tx.write(Ok(None)).await;
98+
trailers_tx.write(Ok(None)).await.unwrap();
10299
anyhow::Ok(())
103100
},
104101
async {
105102
transmit
106103
.await
107104
.expect("transmit sender dropped")
108-
.expect("failed to receive request transmit result")
109105
.context("failed to transmit request")?;
110106
Ok(())
111107
},
@@ -115,12 +111,10 @@ pub async fn request(
115111
let headers = response.headers().entries();
116112

117113
let (body, trailers) = response.body().expect("failed to get response body");
118-
let body = body.try_collect::<Vec<_>>().await?;
119-
let body = body.concat();
114+
let body = body.collect().await;
120115
let trailers = trailers
121116
.await
122117
.expect("trailers sender dropped")
123-
.expect("failed to receive response trailers result")
124118
.context("failed to read body")?;
125119
let trailers = trailers.map(|trailers| trailers.entries());
126120
Ok(Response {

0 commit comments

Comments
 (0)