Skip to content

Commit

Permalink
tests(lib) catch possible 'dispatch_http_call' failures
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Nov 13, 2024
1 parent 8aadfa5 commit 9238d4a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 11 deletions.
1 change: 1 addition & 0 deletions t/lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions t/lib/proxy-wasm-tests/context-checks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,23 @@ impl HttpContext for TestHttp {
.get_config("on_http_dispatch_response")
.is_some()
{
let _ = self.dispatch_http_call(
match self.dispatch_http_call(
self.tester.get_config("host").unwrap_or(""),
vec![(":path", "/dispatch"), (":method", "GET")],
None,
vec![],
Duration::from_secs(0),
);
) {
Ok(_) => {}
Err(status) => match status {
Status::BadArgument => error!("dispatch_http_call: bad argument"),
Status::InternalFailure => error!("dispatch_http_call: internal failure"),
status => panic!(
"dispatch_http_call: unexpected status \"{}\"",
status as u32
),
},
}

return Action::Pause;
}
Expand Down
15 changes: 12 additions & 3 deletions t/lib/proxy-wasm-tests/hostcalls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,23 @@ impl RootContext for TestRoot {

info!("call {}", self.n_sync_calls);

self.dispatch_http_call(
match self.dispatch_http_call(
self.get_config("host").unwrap_or(""),
headers,
self.get_config("body").map(|v| v.as_bytes()),
vec![],
timeout,
)
.unwrap();
) {
Ok(_) => {}
Err(status) => match status {
Status::BadArgument => error!("dispatch_http_call: bad argument"),
Status::InternalFailure => error!("dispatch_http_call: internal failure"),
status => panic!(
"dispatch_http_call: unexpected status \"{}\"",
status as u32
),
},
}
}
_ => (),
}
Expand Down
15 changes: 12 additions & 3 deletions t/lib/proxy-wasm-tests/hostcalls/src/types/test_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,22 @@ impl TestHttp {
None => self.get_config("host").unwrap_or(""),
};

self.dispatch_http_call(
match self.dispatch_http_call(
host,
headers,
self.get_config("body").map(|v| v.as_bytes()),
vec![],
timeout,
)
.unwrap();
) {
Ok(_) => {}
Err(status) => match status {
Status::BadArgument => error!("dispatch_http_call: bad argument"),
Status::InternalFailure => error!("dispatch_http_call: internal failure"),
status => panic!(
"dispatch_http_call: unexpected status \"{}\"",
status as u32
),
},
}
}
}
1 change: 1 addition & 0 deletions t/lib/proxy-wasm-tests/rust-sdk-ver-zero-one/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ crate-type = ["cdylib"]
[dependencies]
proxy-wasm = "0.1"
http = "0.2"
log = "0.4"
19 changes: 16 additions & 3 deletions t/lib/proxy-wasm-tests/rust-sdk-ver-zero-one/src/filter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::single_match)]

use http::StatusCode;
use log::*;
use proxy_wasm::{traits::*, types::*};
use std::collections::HashMap;
use std::time::Duration;
Expand Down Expand Up @@ -88,7 +89,7 @@ impl HttpContext for TestHttpHostcalls {
if let Some(test) = self.config.get("test") {
match test.as_str() {
"dispatch" => {
self.dispatch_http_call(
match self.dispatch_http_call(
self.config.get("host").map(|v| v.as_str()).unwrap_or(""),
vec![
(":method", "GET"),
Expand All @@ -104,8 +105,20 @@ impl HttpContext for TestHttpHostcalls {
self.config.get("body").map(|v| v.as_bytes()),
vec![],
Duration::from_secs(3),
)
.unwrap();
) {
Ok(_) => {}
Err(status) => match status {
Status::BadArgument => error!("dispatch_http_call: bad argument"),
Status::InternalFailure => {
error!("dispatch_http_call: internal failure")
}
status => panic!(
"dispatch_http_call: unexpected status \"{}\"",
status as u32
),
},
}

return Action::Pause;
}
"proxy_get_header_map_value" => {
Expand Down

0 comments on commit 9238d4a

Please sign in to comment.