Skip to content

Commit f10f708

Browse files
authored
Add more test domains. (#12898)
Taken from the `tls_sample_application` tests
1 parent 9c3ed19 commit f10f708

2 files changed

Lines changed: 31 additions & 9 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ fn main() {
55
// Valid domains
66
resolve("localhost").unwrap();
77

8-
resolve_at_least_one_of(&["example.com", "api.github.com"]);
8+
resolve_at_least_one_of(&[
9+
"example.com",
10+
"api.github.com",
11+
"docs.wasmtime.dev",
12+
"bytecodealliance.org",
13+
"www.rust-lang.org",
14+
]);
915

1016
// NB: this is an actual real resolution, so it might time out, might cause
1117
// issues, etc. This result is ignored to prevent flaky failures in CI.

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use futures::join;
21
use test_programs::p3::wasi::sockets::ip_name_lookup::{ErrorCode, resolve_addresses};
32
use test_programs::p3::wasi::sockets::types::IpAddress;
43

@@ -14,16 +13,33 @@ async fn resolve_one(name: &str) -> Result<IpAddress, ErrorCode> {
1413
.to_owned())
1514
}
1615

16+
/// Attempts to resolve at least one of `domains`. Allows failure so long as one
17+
/// succeeds. Intended to help make this test less flaky while still also
18+
/// testing live services.
19+
async fn resolve_at_least_one_of(domains: &[&str]) {
20+
for domain in domains {
21+
match resolve_one(domain).await {
22+
Ok(_) => return,
23+
Err(e) => eprintln!("failed to resolve `{domain}`: {e}"),
24+
}
25+
}
26+
27+
panic!("should have been able to resolve at least one domain");
28+
}
29+
1730
impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
1831
async fn run() -> Result<(), ()> {
1932
// Valid domains
20-
let (res0, res1) = join!(
21-
resolve_addresses("localhost".into()),
22-
resolve_addresses("example.com".into())
23-
);
24-
if res0.is_err() && res1.is_err() {
25-
panic!("should have been able to resolve at least one domain");
26-
}
33+
resolve_one("localhost").await.unwrap();
34+
35+
resolve_at_least_one_of(&[
36+
"example.com",
37+
"api.github.com",
38+
"docs.wasmtime.dev",
39+
"bytecodealliance.org",
40+
"www.rust-lang.org",
41+
])
42+
.await;
2743

2844
// NB: this is an actual real resolution, so it might time out, might cause
2945
// issues, etc. This result is ignored to prevent flaky failures in CI.

0 commit comments

Comments
 (0)