Skip to content

Commit

Permalink
fix test regressions and clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej committed Dec 11, 2024
1 parent a5beae7 commit 2ced60d
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 61 deletions.
2 changes: 1 addition & 1 deletion crates/misc/component-async-tests/http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
[dependencies]
anyhow = { workspace = true }
futures = { workspace = true }
wasmtime = { workspace = true }
wasmtime = { workspace = true, features = ["component-model-async"] }
4 changes: 2 additions & 2 deletions crates/test-programs/src/bin/api_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ impl test_programs::proxy::exports::wasi::http::incoming_handler::Guest for T {
);

assert!(req_hdrs.delete(&header).is_err());
assert!(req_hdrs.append(&header, &b"no".to_vec()).is_err());
assert!(req_hdrs.append(&header, b"no".as_ref()).is_err());

assert!(
!req_hdrs.has(&header),
"append of forbidden header succeeded"
);

assert!(
!req_hdrs.has(&"host".to_owned()),
!req_hdrs.has("host"),
"forbidden host header present in incoming request"
);

Expand Down
2 changes: 0 additions & 2 deletions crates/test-programs/src/bin/async_backpressure_callee.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(warnings)]

mod bindings {
wit_bindgen::generate!({
path: "../misc/component-async-tests/wit",
Expand Down
2 changes: 0 additions & 2 deletions crates/test-programs/src/bin/async_backpressure_caller.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(warnings)]

mod bindings {
wit_bindgen::generate!({
path: "../misc/component-async-tests/wit",
Expand Down
2 changes: 0 additions & 2 deletions crates/test-programs/src/bin/async_http_echo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(warnings)]

mod bindings {
wit_bindgen::generate!({
path: "../misc/component-async-tests/wit",
Expand Down
2 changes: 0 additions & 2 deletions crates/test-programs/src/bin/async_http_middleware.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(warnings)]

mod bindings {
wit_bindgen::generate!({
path: "../misc/component-async-tests/wit",
Expand Down
9 changes: 2 additions & 7 deletions crates/test-programs/src/bin/async_poll.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(warnings)]

mod bindings {
wit_bindgen::generate!({
path: "../misc/component-async-tests/wit",
Expand All @@ -10,10 +8,7 @@ mod bindings {
export!(Component);
}

use {
bindings::{exports::local::local::run::Guest, local::local::ready},
std::ptr,
};
use bindings::{exports::local::local::run::Guest, local::local::ready};

fn task_poll() -> Option<(i32, i32, i32)> {
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -50,7 +45,7 @@ fn async_when_ready() -> i32 {
#[link_name = "[async]when-ready"]
fn call_when_ready(_: *mut u8, _: *mut u8) -> i32;
}
unsafe { call_when_ready(ptr::null_mut(), ptr::null_mut()) }
unsafe { call_when_ready(std::ptr::null_mut(), std::ptr::null_mut()) }
}
}

Expand Down
12 changes: 6 additions & 6 deletions crates/test-programs/src/bin/async_round_trip_stackful.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(warnings)]

// This tests callback-less (AKA stackful) async exports.
//
// Testing this case using Rust's LLVM-based toolchain is tricky because, as of
Expand All @@ -22,7 +20,7 @@ extern "C" {
fn task_return_foo(ptr: *mut u8, len: usize);
}
#[cfg(not(target_arch = "wasm32"))]
extern "C" fn task_return_foo(ptr: *mut u8, len: usize) {
extern "C" fn task_return_foo(_ptr: *mut u8, _len: usize) {
unreachable!()
}

Expand All @@ -33,7 +31,7 @@ extern "C" {
fn import_foo(params: *mut u8, results: *mut u8) -> u32;
}
#[cfg(not(target_arch = "wasm32"))]
extern "C" fn import_foo(params: *mut u8, results: *mut u8) -> u32 {
extern "C" fn import_foo(_params: *mut u8, _results: *mut u8) -> u32 {
unreachable!()
}

Expand All @@ -44,7 +42,9 @@ extern "C" {
fn task_wait(results: *mut i32) -> i32;
}
#[cfg(not(target_arch = "wasm32"))]
extern "C" fn task_wait(results: *mut i32) -> i32;
extern "C" fn task_wait(_results: *mut i32) -> i32 {
unreachable!()
}

#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "$root")]
Expand All @@ -53,7 +53,7 @@ extern "C" {
fn subtask_drop(task: u32);
}
#[cfg(not(target_arch = "wasm32"))]
extern "C" fn subtask_drop(task: u32) {
extern "C" fn subtask_drop(_task: u32) {
unreachable!()
}

Expand Down
2 changes: 0 additions & 2 deletions crates/test-programs/src/bin/async_round_trip_stackless.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(warnings)]

mod bindings {
wit_bindgen::generate!({
path: "../misc/component-async-tests/wit",
Expand Down
2 changes: 0 additions & 2 deletions crates/test-programs/src/bin/async_round_trip_synchronous.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(warnings)]

mod bindings {
wit_bindgen::generate!({
path: "../misc/component-async-tests/wit",
Expand Down
2 changes: 0 additions & 2 deletions crates/test-programs/src/bin/async_round_trip_wait.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(warnings)]

mod bindings {
wit_bindgen::generate!({
path: "../misc/component-async-tests/wit",
Expand Down
2 changes: 0 additions & 2 deletions crates/test-programs/src/bin/async_transmit_callee.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(warnings)]

mod bindings {
wit_bindgen::generate!({
path: "../misc/component-async-tests/wit",
Expand Down
2 changes: 0 additions & 2 deletions crates/test-programs/src/bin/async_transmit_caller.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(warnings)]

mod bindings {
wit_bindgen::generate!({
path: "../misc/component-async-tests/wit",
Expand Down
2 changes: 0 additions & 2 deletions crates/test-programs/src/bin/async_yield_callee.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(warnings)]

mod bindings {
wit_bindgen::generate!({
path: "../misc/component-async-tests/wit",
Expand Down
2 changes: 0 additions & 2 deletions crates/test-programs/src/bin/async_yield_caller.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(warnings)]

mod bindings {
wit_bindgen::generate!({
path: "../misc/component-async-tests/wit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,42 @@ use test_programs::wasi::http::types::{HeaderError, Headers, OutgoingRequest};
fn main() {
let hdrs = Headers::new();
assert!(matches!(
hdrs.append(&"malformed header name".to_owned(), &b"ok value".to_vec()),
hdrs.append("malformed header name", b"ok value".as_ref()),
Err(HeaderError::InvalidSyntax)
));

assert!(matches!(
hdrs.append(&"ok-header-name".to_owned(), &b"ok value".to_vec()),
hdrs.append("ok-header-name", b"ok value".as_ref()),
Ok(())
));

assert!(matches!(
hdrs.append(&"ok-header-name".to_owned(), &b"bad\nvalue".to_vec()),
hdrs.append("ok-header-name", b"bad\nvalue".as_ref()),
Err(HeaderError::InvalidSyntax)
));

assert!(matches!(
hdrs.append(&"Connection".to_owned(), &b"keep-alive".to_vec()),
hdrs.append("Connection", b"keep-alive".as_ref()),
Err(HeaderError::Forbidden)
));

assert!(matches!(
hdrs.append(&"Keep-Alive".to_owned(), &b"stuff".to_vec()),
hdrs.append("Keep-Alive", b"stuff".as_ref()),
Err(HeaderError::Forbidden)
));

assert!(matches!(
hdrs.append(&"Host".to_owned(), &b"example.com".to_vec()),
hdrs.append("Host", b"example.com".as_ref()),
Err(HeaderError::Forbidden)
));

assert!(matches!(
hdrs.append(
&"custom-forbidden-header".to_owned(),
&b"keep-alive".to_vec()
),
hdrs.append("custom-forbidden-header", b"keep-alive".as_ref()),
Err(HeaderError::Forbidden)
));

assert!(matches!(
hdrs.append(
&"Custom-Forbidden-Header".to_owned(),
&b"keep-alive".to_vec()
),
hdrs.append("Custom-Forbidden-Header", b"keep-alive".as_ref()),
Err(HeaderError::Forbidden)
));

Expand All @@ -67,17 +61,17 @@ fn main() {
let hdrs = req.headers();

assert!(matches!(
hdrs.set(&"Content-Length".to_owned(), &[b"10".to_vec()]),
hdrs.set("Content-Length", &[b"10".to_vec()]),
Err(HeaderError::Immutable),
));

assert!(matches!(
hdrs.append(&"Content-Length".to_owned(), &b"10".to_vec()),
hdrs.append("Content-Length", b"10".as_ref()),
Err(HeaderError::Immutable),
));

assert!(matches!(
hdrs.delete(&"Content-Length".to_owned()),
hdrs.delete("Content-Length"),
Err(HeaderError::Immutable),
));
}
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/component/concurrent/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl Table {
fn push_(&mut self, e: TableEntry) -> Result<u32, TableError> {
if let Some(free) = self.pop_free_list() {
self.entries[free] = Entry::Occupied { entry: e };
Ok(free as u32)
Ok(u32::try_from(free).unwrap())
} else {
let ix = self
.entries
Expand Down
20 changes: 15 additions & 5 deletions crates/wasmtime/src/runtime/component/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,21 @@ impl<T> LinkerInstance<'_, T> {
let dtor = Arc::new(crate::func::HostFunc::wrap_inner(
&self.engine,
move |mut cx: crate::Caller<'_, T>, (param,): (u32,)| {
let async_cx = cx.as_context_mut().0.async_cx().expect("async cx");
let mut future = Pin::from(dtor(cx.as_context_mut(), param));
match unsafe { async_cx.block_on(future.as_mut()) } {
Ok(Ok(())) => Ok(()),
Ok(Err(trap)) | Err(trap) => Err(trap),
#[cfg(feature = "component-model-async")]
{
let async_cx =
crate::component::concurrent::AsyncCx::new(&mut cx.as_context_mut());
let mut future = Pin::from(dtor(cx.as_context_mut(), param));
unsafe { async_cx.block_on(future.as_mut(), None::<StoreContextMut<'_, T>>) }?.0
}
#[cfg(not(feature = "component-model-async"))]
{
let async_cx = cx.as_context_mut().0.async_cx().expect("async cx");
let mut future = Pin::from(dtor(cx.as_context_mut(), param));
match unsafe { async_cx.block_on(future.as_mut()) } {
Ok(Ok(())) => Ok(()),
Ok(Err(trap)) | Err(trap) => Err(trap),
}
}
},
));
Expand Down

0 comments on commit 2ced60d

Please sign in to comment.