Skip to content

Commit

Permalink
Fix flaky integration tests for log_crate_proxy by adding a mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO committed Mar 21, 2024
1 parent dbfba76 commit 22b48a8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion spdlog/tests/log_crate_proxy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::sync::{Arc, Mutex};

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

Expand All @@ -8,6 +8,8 @@ include!(concat!(
));
use test_utils::*;

static GLOBAL_LOG_CRATE_PROXY_MUTEX: Mutex<()> = Mutex::new(());

#[cfg(feature = "log")]
#[test]
fn test_source_location() {
Expand All @@ -17,6 +19,7 @@ fn test_source_location() {
let sink = Arc::new(StringSink::with(|b| b.formatter(formatter)));
let logger = Arc::new(build_test_logger(|b| b.sink(sink.clone())));

let _guard = GLOBAL_LOG_CRATE_PROXY_MUTEX.lock().unwrap();
spdlog::init_log_crate_proxy().ok();
spdlog::log_crate_proxy().set_logger(Some(logger));
log::set_max_level(log::LevelFilter::Trace);
Expand All @@ -35,6 +38,7 @@ fn test_target() {
let sink = Arc::new(StringSink::with(|b| b.formatter(formatter)));
let logger = Arc::new(build_test_logger(|b| b.sink(sink.clone())));

let _guard = GLOBAL_LOG_CRATE_PROXY_MUTEX.lock().unwrap();
spdlog::init_log_crate_proxy().ok();
spdlog::log_crate_proxy().set_logger(Some(logger));
log::set_max_level(log::LevelFilter::Trace);
Expand Down

0 comments on commit 22b48a8

Please sign in to comment.