mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-28 02:18:50 +00:00
Currently, the platform-specific code for controlling DNS resolution on a system sits in `firezone-headless-client`. This code is also used by the GUI client. This creates a weird compile-time dependency from the GUI client to the headless client. For other components that have platform-specific implementations, we use the `firezone-bin-shared` crate. As a first step of resolving the compile-time dependency, we move the `dns_control` module to `firezone-bin-shared`.
46 lines
1.6 KiB
Rust
46 lines
1.6 KiB
Rust
#![allow(clippy::unwrap_used)]
|
|
|
|
use firezone_bin_shared::{DnsControlMethod, new_dns_notifier, new_network_notifier};
|
|
use futures::future::FutureExt as _;
|
|
use std::time::Duration;
|
|
use tokio::time::timeout;
|
|
|
|
/// Smoke test for the DNS and network change notifiers
|
|
///
|
|
/// Turn them on, wait a second, turn them off.
|
|
/// This tests that the threads quit gracefully when we call `close`, and they don't crash on startup.
|
|
#[tokio::test]
|
|
async fn notifiers() {
|
|
firezone_logging::test_global("debug");
|
|
let tokio_handle = tokio::runtime::Handle::current();
|
|
|
|
let mut dns = new_dns_notifier(tokio_handle.clone(), DnsControlMethod::default())
|
|
.await
|
|
.unwrap();
|
|
let mut net = new_network_notifier(tokio_handle, DnsControlMethod::default())
|
|
.await
|
|
.unwrap();
|
|
|
|
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
|
|
|
// The notifiers always notify once they start listening for changes, to avoid gaps during startup.
|
|
timeout(Duration::from_secs(1), dns.notified())
|
|
.await
|
|
.unwrap()
|
|
.unwrap();
|
|
timeout(Duration::from_secs(1), net.notified())
|
|
.await
|
|
.unwrap()
|
|
.unwrap();
|
|
|
|
// After that first notification, we shouldn't get any other notifications during a normal unit test.
|
|
|
|
assert!(dns.notified().now_or_never().is_none());
|
|
assert!(net.notified().now_or_never().is_none());
|
|
|
|
// `close` consumes the notifiers, so we can catch errors and can't call any methods on a closed notifier. If the notifier is dropped, we internally call the same code that `close` calls.
|
|
|
|
dns.close().unwrap();
|
|
net.close().unwrap();
|
|
}
|