Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into ja-explore-opt-in-dnssec
Browse files Browse the repository at this point in the history
  • Loading branch information
justahero authored May 13, 2024
2 parents 7281b45 + fe3961f commit 1efc6a1
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
9 changes: 7 additions & 2 deletions packages/dns-test/src/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ impl Implementation {
match self {
Implementation::Bind => &["named", "-g", "-d5"],

Implementation::Hickory(_) => &["hickory-dns", "-d"],
Implementation::Hickory(_) => &[
"sh",
"-c",
"echo $$ > /tmp/hickory.pid
exec hickory-dns -d",
],

Implementation::Unbound => match role {
Role::NameServer => &["nsd", "-d"],
Expand All @@ -146,7 +151,7 @@ impl Implementation {
match self {
Implementation::Bind => "/tmp/named.pid",

Implementation::Hickory(_) => unimplemented!(),
Implementation::Hickory(_) => "/tmp/hickory.pid",

Implementation::Unbound => match role {
Role::NameServer => "/tmp/nsd.pid",
Expand Down
37 changes: 36 additions & 1 deletion packages/dns-test/src/name_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,10 @@ kill -TERM $(cat {pidfile})"
self.container.status_ok(&["sh", "-c", &kill])?;
let output = self.state.child.wait()?;

if !output.status.success() {
// the hickory-dns binary does not do signal handling so it won't shut down gracefully; we
// will still get some logs so we'll ignore the fact that it fails to shut down ...
let is_hickory = matches!(self.implementation, Implementation::Hickory(_));
if !is_hickory && !output.status.success() {
return Err(
format!("could not terminate the `{}` process", self.implementation).into(),
);
Expand Down Expand Up @@ -431,8 +434,12 @@ fn admin_ns(ns_count: usize) -> FQDN {

#[cfg(test)]
mod tests {
use std::thread;
use std::time::Duration;

use crate::client::{Client, DigSettings};
use crate::record::RecordType;
use crate::Repository;

use super::*;

Expand Down Expand Up @@ -532,4 +539,32 @@ mod tests {

Ok(())
}

#[test]
fn terminate_hickory_works() -> Result<()> {
let network = Network::new()?;
let ns = NameServer::new(
&Implementation::Hickory(Repository("https://github.com/hickory-dns/hickory-dns")),
FQDN::ROOT,
&network,
)?
.start()?;

// hickory-dns does not do signal handling so we need to wait until it prints something to
// the console
thread::sleep(Duration::from_millis(500));

let logs = ns.terminate()?;

eprintln!("{logs}");
let mut found = false;
for line in logs.lines() {
if line.contains("Hickory DNS") && line.contains("starting") {
found = true;
}
}
assert!(found);

Ok(())
}
}
33 changes: 30 additions & 3 deletions packages/dns-test/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ kill -TERM $(cat {pidfile})"
self.container.status_ok(&["sh", "-c", &kill])?;
let output = self.child.wait()?;

if !output.status.success() {
return Err("could not terminate the `unbound` process".into());
// the hickory-dns binary does not do signal handling so it won't shut down gracefully; we
// will still get some logs so we'll ignore the fact that it fails to shut down ...
let is_hickory = matches!(self.implementation, Implementation::Hickory(_));
if !is_hickory && !output.status.success() {
return Err(
format!("could not terminate the `{}` process", self.implementation).into(),
);
}

assert!(
Expand Down Expand Up @@ -148,7 +153,7 @@ impl ResolverSettings {

#[cfg(test)]
mod tests {
use crate::{name_server::NameServer, FQDN};
use crate::{name_server::NameServer, Repository, FQDN};

use super::*;

Expand Down Expand Up @@ -179,4 +184,26 @@ mod tests {

Ok(())
}

#[test]
fn terminate_hickory_works() -> Result<()> {
let network = Network::new()?;
let ns = NameServer::new(&Implementation::Unbound, FQDN::ROOT, &network)?.start()?;
let resolver = Resolver::new(&network, Root::new(ns.fqdn().clone(), ns.ipv4_addr()))
.start(&Implementation::Hickory(Repository(
"https://github.com/hickory-dns/hickory-dns",
)))?;
let logs = resolver.terminate()?;

eprintln!("{logs}");
let mut found = false;
for line in logs.lines() {
if line.contains("Hickory DNS") && line.contains("starting") {
found = true;
}
}
assert!(found);

Ok(())
}
}

0 comments on commit 1efc6a1

Please sign in to comment.