Skip to content

Commit 2cdb680

Browse files
committed
chore(api,tests): verify that DNS resolver has at least one DNS server configured
1 parent f4c43bd commit 2cdb680

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

src/network/dns_resolver.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl DnsResolver for TokioDnsResolver {
3838

3939
#[cfg(test)]
4040
pub mod tests {
41-
use crate::network::DnsResolver;
41+
use crate::network::{DnsResolver, TokioDnsResolver};
4242
use futures::future::BoxFuture;
4343
use hickory_resolver::{
4444
lookup::Lookup,
@@ -93,4 +93,29 @@ pub mod tests {
9393
}
9494
}
9595
}
96+
97+
/// Companion to the test above: actually exercise `create()` end-to-end and assert
98+
/// that lookups against a non-existent domain do **not** fail with the empty-
99+
/// `name_servers` error mode. We do not assert success because CI/sandbox network
100+
/// reachability is out of our control, but the "no connections available" sentinel
101+
/// is produced locally by hickory before any network I/O and so is detectable
102+
/// regardless of outbound connectivity.
103+
#[tokio::test]
104+
async fn create_yields_resolver_that_does_not_short_circuit_on_empty_name_servers() {
105+
let resolver = TokioDnsResolver::create().expect("TokioDnsResolver should build");
106+
// The lookup itself may succeed (NXDOMAIN response) or fail with a network error
107+
// depending on outbound DNS reachability of the test environment, neither of
108+
// which we want to assert on. What we *do* assert is that the failure mode
109+
// (if any) is not the `no connections available` sentinel that hickory raises
110+
// synchronously, before any network I/O, when `name_servers` is empty.
111+
if let Err(err) = resolver
112+
.lookup_ip("nonexistent-retrack-regression-guard.example.")
113+
.await
114+
{
115+
assert!(
116+
!err.to_string().contains("no connections available"),
117+
"DNS resolver appears to have no configured name servers: {err}"
118+
);
119+
}
120+
}
96121
}

0 commit comments

Comments
 (0)