Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src-tauri/crates/mhost-dns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,19 @@ pub const MHOST_DNS_PORT: u16 = 1053;
/// 非 macOS 平台没有端口转发机制,直接监听 53。
#[cfg(not(target_os = "macos"))]
pub const MHOST_DNS_PORT: u16 = 53;

/// **fix (issue #148 review 🟡 #2)**:跨 crate 测试串行化锁。
///
/// mhost-dns 平台侧 test 与 mhost crate 里的 `cleanup_dns_on_exit` test
/// 都会改 `MHOST_RUNTIME_DIR` —— 它们在 cargo test 下是独立二进制,
/// `proxy::tests::TEST_LOCK` 是 `pub(crate)`,跨 crate 看不到。
///
/// 这里暴露一个公开锁,让两边的测试都引用同一把 mutex,避免 env var
/// race(proxy pid_file 在一边被写,另一边同时改 runtime_dir 读到错的路径)。
///
/// **`#[cfg(test)]` 不行**:mhost crate 编译 test 时把 mhost_dns 作为依赖,
/// mhost_dns 自身的 `cfg(test)` 不被启用,这个 static 看不到。所以 always-on
/// + `#[doc(hidden)]` 阻止出现在公共 API 文档里;零运行时成本(Mutex
/// lazy-init)。
#[doc(hidden)]
pub static RUNTIME_DIR_TEST_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
Loading
Loading