Skip to content

Commit a6d05f7

Browse files
committed
Fix spin-factor-outbound-http tests
These two tests worked on the assumption that connections to the IPv6 "Discard Prefix" would always result in "connection refused". This is apparently not the case, so additionally set a very short connect timeout and treat timeout as 'success' as well. Signed-off-by: Lann Martin <[email protected]>
1 parent d08fbda commit a6d05f7

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,24 @@ async fn allowed_host_is_allowed() -> anyhow::Result<()> {
2424
let mut state = test_instance_state("https://*", true).await?;
2525
let mut wasi_http = OutboundHttpFactor::get_wasi_http_impl(&mut state).unwrap();
2626

27-
// [100::] is an IPv6 "black hole", which should always fail
27+
// [100::] is the IPv6 "Discard Prefix", which should always fail
2828
let req = Request::get("https://[100::1]:443").body(Default::default())?;
2929
let mut future_resp = wasi_http.send_request(req, test_request_config())?;
3030
future_resp.ready().await;
3131

32-
// We don't want to make an actual network request, so treat "connection refused" as success
32+
// Different systems handle the discard prefix differently; some will
33+
// immediately reject it while others will silently let it time out
3334
match future_resp.unwrap_ready().unwrap() {
34-
Ok(_) => bail!("expected Err, got Ok"),
35-
Err(err) => assert!(matches!(err, ErrorCode::ConnectionRefused), "{err:?}"),
35+
Err(ErrorCode::ConnectionRefused | ErrorCode::ConnectionTimeout) => (),
36+
other => bail!("expected Err(ConnectionRefused | ConnectionTimeout), got {other:?}"),
3637
};
3738
Ok(())
3839
}
3940

4041
#[tokio::test]
4142
async fn self_request_smoke_test() -> anyhow::Result<()> {
4243
let mut state = test_instance_state("http://self", true).await?;
44+
// [100::] is the IPv6 "Discard Prefix", which should always fail
4345
let origin = SelfRequestOrigin::from_uri(&Uri::from_static("http://[100::1]"))?;
4446
state.http.set_self_request_origin(origin);
4547

@@ -48,10 +50,11 @@ async fn self_request_smoke_test() -> anyhow::Result<()> {
4850
let mut future_resp = wasi_http.send_request(req, test_request_config())?;
4951
future_resp.ready().await;
5052

51-
// We don't want to make an actual network request, so treat "connection refused" as success
53+
// Different systems handle the discard prefix differently; some will
54+
// immediately reject it while others will silently let it time out
5255
match future_resp.unwrap_ready().unwrap() {
53-
Ok(_) => bail!("expected Err, got Ok"),
54-
Err(err) => assert!(matches!(err, ErrorCode::ConnectionRefused), "{err:?}"),
56+
Err(ErrorCode::ConnectionRefused | ErrorCode::ConnectionTimeout) => (),
57+
other => bail!("expected Err(ConnectionRefused | ConnectionTimeout), got {other:?}"),
5558
};
5659
Ok(())
5760
}
@@ -134,8 +137,8 @@ async fn test_instance_state(
134137
fn test_request_config() -> OutgoingRequestConfig {
135138
OutgoingRequestConfig {
136139
use_tls: false,
137-
connect_timeout: Duration::from_secs(60),
138-
first_byte_timeout: Duration::from_secs(60),
139-
between_bytes_timeout: Duration::from_secs(60),
140+
connect_timeout: Duration::from_millis(1),
141+
first_byte_timeout: Duration::from_millis(1),
142+
between_bytes_timeout: Duration::from_millis(1),
140143
}
141144
}

0 commit comments

Comments
 (0)