|
6 | 6 |
|
7 | 7 | use std::time::Duration; |
8 | 8 |
|
| 9 | +#[cfg(target_os = "android")] |
| 10 | +use iroh_dns::dns::DnsProtocol; |
9 | 11 | use iroh_dns::dns::DnsResolver; |
10 | 12 |
|
11 | 13 | const TIMEOUT: Duration = Duration::from_secs(8); |
12 | 14 | const HOST: &str = "dns.iroh.link"; |
13 | 15 |
|
14 | | -#[tokio::test] |
15 | | -async fn resolver_constructs_without_panic() { |
16 | | - let _resolver = DnsResolver::new(); |
17 | | -} |
18 | | - |
19 | | -// Ignored on Android: in the GitHub-hosted emulator the public DNS |
20 | | -// fallback's hickory connection pool repeatedly returns |
21 | | -// "no connections available" within ~30 ms, well before the 8s |
22 | | -// per-lookup timeout, so a resolution that works locally fails in |
23 | | -// CI. Tracking the actual fix separately; see Frando/android-dns-fix. |
24 | | -#[cfg_attr( |
25 | | - target_os = "android", |
26 | | - ignore = "flaky on emulator (no connections available)" |
27 | | -)] |
28 | 16 | #[tokio::test] |
29 | 17 | async fn resolver_resolves_dns_iroh_link() { |
30 | 18 | let resolver = DnsResolver::new(); |
@@ -54,3 +42,33 @@ async fn resolver_resolves_dns_iroh_link() { |
54 | 42 | ); |
55 | 43 | eprintln!("{HOST} resolved to: {hits:?}"); |
56 | 44 | } |
| 45 | + |
| 46 | +/// Resolves through the Android emulator's QEMU NAT DNS proxy. |
| 47 | +/// |
| 48 | +/// 10.0.2.3 is the well-known emulator DNS gateway, documented at |
| 49 | +/// <https://developer.android.com/studio/run/emulator-networking>. |
| 50 | +/// Pointing the resolver at it explicitly sidesteps the missing |
| 51 | +/// system-DNS reader (no JNI context here) so this test exercises |
| 52 | +/// hickory's pool, sockets, and our `DnsResolver` plumbing against a |
| 53 | +/// nameserver that is always reachable inside the emulator, |
| 54 | +/// independent of whether public DNS is reachable on the runner. |
| 55 | +#[cfg(target_os = "android")] |
| 56 | +#[tokio::test] |
| 57 | +async fn resolves_via_emulator_dns_proxy() { |
| 58 | + let nameserver = "10.0.2.3:53".parse().unwrap(); |
| 59 | + let resolver = DnsResolver::builder() |
| 60 | + .with_nameserver(nameserver, DnsProtocol::Udp) |
| 61 | + .build(); |
| 62 | + |
| 63 | + let addrs: Vec<_> = resolver |
| 64 | + .lookup_ipv4(HOST, TIMEOUT) |
| 65 | + .await |
| 66 | + .expect("IPv4 lookup via 10.0.2.3 should succeed in the emulator") |
| 67 | + .collect(); |
| 68 | + |
| 69 | + assert!( |
| 70 | + !addrs.is_empty(), |
| 71 | + "expected at least one A record for {HOST} via 10.0.2.3", |
| 72 | + ); |
| 73 | + eprintln!("{HOST} resolved via 10.0.2.3 to: {addrs:?}"); |
| 74 | +} |
0 commit comments