Skip to content

Commit 2963325

Browse files
committed
fix: config test race condition with env var mutex
1 parent a38497f commit 2963325

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,13 @@ fn env_parse<T: std::str::FromStr>(key: &str, default: T) -> T {
127127
#[cfg(test)]
128128
mod tests {
129129
use super::*;
130+
use std::sync::Mutex;
131+
132+
static ENV_LOCK: Mutex<()> = Mutex::new(());
130133

131134
#[test]
132135
fn test_config_defaults() {
136+
let _lock = ENV_LOCK.lock().unwrap();
133137
let cfg = Config::from_env().expect("default config should be valid");
134138
assert_eq!(cfg.port, DEFAULT_PORT);
135139
assert_eq!(cfg.max_concurrent_tasks, DEFAULT_MAX_CONCURRENT);
@@ -144,6 +148,7 @@ mod tests {
144148

145149
#[test]
146150
fn test_config_rejects_zero_threshold() {
151+
let _lock = ENV_LOCK.lock().unwrap();
147152
std::env::set_var("CONSENSUS_THRESHOLD", "0.0");
148153
let result = Config::from_env();
149154
std::env::remove_var("CONSENSUS_THRESHOLD");
@@ -155,6 +160,7 @@ mod tests {
155160

156161
#[test]
157162
fn test_config_rejects_threshold_above_one() {
163+
let _lock = ENV_LOCK.lock().unwrap();
158164
std::env::set_var("CONSENSUS_THRESHOLD", "1.5");
159165
let result = Config::from_env();
160166
std::env::remove_var("CONSENSUS_THRESHOLD");

0 commit comments

Comments
 (0)