Skip to content

Commit 902444c

Browse files
committed
factor-outbound-http: Make test error handling even robuster
Signed-off-by: Lann Martin <[email protected]>
1 parent d1eb9ac commit 902444c

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

crates/factor-outbound-http/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use spin_factors::{
2525
use wasmtime_wasi_http::WasiHttpCtx;
2626

2727
pub use wasmtime_wasi_http::{
28+
bindings::http::types::ErrorCode,
2829
body::HyperOutgoingBody,
2930
types::{HostFutureIncomingResponse, OutgoingRequestConfig},
3031
HttpResult,

crates/factor-outbound-http/tests/factor_test.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use std::time::Duration;
33
use anyhow::bail;
44
use http::{Request, Uri};
55
use spin_common::{assert_matches, assert_not_matches};
6-
use spin_factor_outbound_http::{OutboundHttpFactor, SelfRequestOrigin};
6+
use spin_factor_outbound_http::{
7+
ErrorCode, HostFutureIncomingResponse, OutboundHttpFactor, SelfRequestOrigin,
8+
};
79
use spin_factor_outbound_networking::OutboundNetworkingFactor;
810
use spin_factor_variables::VariablesFactor;
911
use spin_factors::{anyhow, RuntimeFactors};
1012
use spin_factors_test::{toml, TestEnvironment};
1113
use wasmtime_wasi::p2::Pollable;
12-
use wasmtime_wasi_http::{
13-
bindings::http::types::ErrorCode, types::OutgoingRequestConfig, WasiHttpView,
14-
};
14+
use wasmtime_wasi_http::{types::OutgoingRequestConfig, WasiHttpView};
1515

1616
#[derive(RuntimeFactors)]
1717
struct TestFactors {
@@ -30,12 +30,7 @@ async fn allowed_host_is_allowed() -> anyhow::Result<()> {
3030
let mut future_resp = wasi_http.send_request(req, test_request_config())?;
3131
future_resp.ready().await;
3232

33-
// Different systems handle the discard prefix differently; some will
34-
// immediately reject it while others will silently let it time out
35-
assert_matches!(
36-
future_resp.unwrap_ready().unwrap(),
37-
Err(ErrorCode::ConnectionRefused | ErrorCode::ConnectionTimeout),
38-
);
33+
assert_discard_prefix_error(future_resp);
3934
Ok(())
4035
}
4136

@@ -51,12 +46,7 @@ async fn self_request_smoke_test() -> anyhow::Result<()> {
5146
let mut future_resp = wasi_http.send_request(req, test_request_config())?;
5247
future_resp.ready().await;
5348

54-
// Different systems handle the discard prefix differently; some will
55-
// immediately reject it while others will silently let it time out
56-
assert_matches!(
57-
future_resp.unwrap_ready().unwrap(),
58-
Err(ErrorCode::ConnectionRefused | ErrorCode::ConnectionTimeout),
59-
);
49+
assert_discard_prefix_error(future_resp);
6050
Ok(())
6151
}
6252

@@ -143,3 +133,15 @@ fn test_request_config() -> OutgoingRequestConfig {
143133
between_bytes_timeout: Duration::from_millis(1),
144134
}
145135
}
136+
137+
fn assert_discard_prefix_error(future_resp: HostFutureIncomingResponse) {
138+
// Different systems handle the discard prefix differently; some will
139+
// immediately reject it while others will silently let it time out
140+
assert_matches!(
141+
future_resp.unwrap_ready().unwrap(),
142+
Err(ErrorCode::ConnectionRefused
143+
| ErrorCode::ConnectionTimeout
144+
| ErrorCode::ConnectionReadTimeout
145+
| ErrorCode::DnsError(_)),
146+
);
147+
}

0 commit comments

Comments
 (0)