From 5918435790d04b1a32dce4a0d5b033cf815a539e Mon Sep 17 00:00:00 2001 From: Floze <88098863+floze-the-genius@users.noreply.github.com> Date: Sun, 19 Jul 2026 00:57:10 +0400 Subject: [PATCH] fix: isolate temporary config paths Give each TempConf instance a process-local atomic suffix so tests can safely reuse descriptive names under parallel execution. Add a regression that verifies same-name configs keep distinct paths and contents.\n\nCloses #35. --- src/cli.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index 4e2f530..4fb25c6 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -474,6 +474,7 @@ mod tests { use super::*; use std::fs; use std::path::Path; + use std::sync::atomic::{AtomicU64, Ordering}; fn parse(args: &[&str]) -> Result { CliArgs::parse(args.iter().map(|s| s.to_string())) @@ -609,6 +610,8 @@ mod tests { // --- Config file integration tests ------------------------------------- + static NEXT_TEMP_CONF_ID: AtomicU64 = AtomicU64::new(0); + struct TempConf { path: PathBuf, } @@ -616,7 +619,11 @@ mod tests { impl TempConf { fn new(name: &str, body: &str) -> Self { let mut dir = std::env::temp_dir(); - dir.push(format!("ferrum-cli-{name}-{}.conf", std::process::id())); + let id = NEXT_TEMP_CONF_ID.fetch_add(1, Ordering::Relaxed); + dir.push(format!( + "ferrum-cli-{name}-{}-{id}.conf", + std::process::id() + )); fs::write(&dir, body).expect("write temp conf"); Self { path: dir } } @@ -628,6 +635,16 @@ mod tests { } } + #[test] + fn temp_conf_paths_are_unique_for_reused_names() { + let first = TempConf::new("reused", "port 7000\n"); + let second = TempConf::new("reused", "port 7001\n"); + + assert_ne!(first.path, second.path); + assert_eq!(fs::read_to_string(&first.path).unwrap(), "port 7000\n"); + assert_eq!(fs::read_to_string(&second.path).unwrap(), "port 7001\n"); + } + #[test] fn config_file_supplies_addr_from_bind_and_port() { let conf = TempConf::new("bind-port", "bind 0.0.0.0\nport 7000\n");