Skip to content

Commit 38cf870

Browse files
committed
Fix flaky integration tests for log_crate_proxy by adding a mutex
1 parent 9dd80ac commit 38cf870

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

spdlog/tests/log_crate_proxy.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::Arc;
1+
use std::sync::{Arc, Mutex};
22

33
use spdlog::formatter::{pattern, PatternFormatter};
44

@@ -8,6 +8,8 @@ include!(concat!(
88
));
99
use test_utils::*;
1010

11+
static GLOBAL_LOG_CRATE_PROXY_MUTEX: Mutex<()> = Mutex::new(());
12+
1113
#[cfg(feature = "log")]
1214
#[test]
1315
fn test_source_location() {
@@ -17,6 +19,7 @@ fn test_source_location() {
1719
let sink = Arc::new(StringSink::with(|b| b.formatter(formatter)));
1820
let logger = Arc::new(build_test_logger(|b| b.sink(sink.clone())));
1921

22+
let _guard = GLOBAL_LOG_CRATE_PROXY_MUTEX.lock().unwrap();
2023
spdlog::init_log_crate_proxy().ok();
2124
spdlog::log_crate_proxy().set_logger(Some(logger));
2225
log::set_max_level(log::LevelFilter::Trace);
@@ -40,6 +43,7 @@ fn test_target() {
4043
let sink = Arc::new(StringSink::with(|b| b.formatter(formatter)));
4144
let logger = Arc::new(build_test_logger(|b| b.sink(sink.clone())));
4245

46+
let _guard = GLOBAL_LOG_CRATE_PROXY_MUTEX.lock().unwrap();
4347
spdlog::init_log_crate_proxy().ok();
4448
spdlog::log_crate_proxy().set_logger(Some(logger));
4549
log::set_max_level(log::LevelFilter::Trace);

0 commit comments

Comments
 (0)