Skip to content

Commit a781d5d

Browse files
committed
Ensure the tracing tests run in an order | Rename the function that changes the log level
Signed-off-by: mabulgu <[email protected]>
1 parent f7e98b2 commit a781d5d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/src/cli.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ impl Cli {
10621062
_ => tracing::Level::TRACE, // -vvv or more
10631063
};
10641064

1065-
bootc_utils::update_tracing(log_level);
1065+
bootc_utils::update_tracing_log_level(log_level);
10661066

10671067
cli
10681068
}
@@ -1370,15 +1370,16 @@ mod tests {
13701370
mod tracing_tests {
13711371
#![allow(unsafe_code)]
13721372

1373-
use bootc_utils::{initialize_tracing, update_tracing};
1373+
use bootc_utils::{initialize_tracing, update_tracing_log_level};
13741374
use nix::unistd::{close, dup, dup2, pipe};
13751375
use std::fs::File;
13761376
use std::io::{self, Read};
13771377
use std::os::unix::io::{AsRawFd, FromRawFd};
1378-
use std::sync::Once;
1378+
use std::sync::{Mutex, Once};
13791379

13801380
// Ensure logging is initialized once to prevent conflicts across tests
13811381
static INIT: Once = Once::new();
1382+
static TEST_MUTEX: Mutex<()> = Mutex::new(());
13821383

13831384
/// Helper function to initialize tracing for tests
13841385
fn init_tracing_for_tests() {
@@ -1421,6 +1422,8 @@ mod tracing_tests {
14211422

14221423
#[test]
14231424
fn test_default_tracing() {
1425+
let _lock = TEST_MUTEX.lock().unwrap(); // Ensure sequential execution
1426+
14241427
init_tracing_for_tests();
14251428

14261429
let output = capture_stderr(|| {
@@ -1435,9 +1438,10 @@ mod tracing_tests {
14351438

14361439
#[test]
14371440
fn test_update_tracing() {
1441+
let _lock = TEST_MUTEX.lock().unwrap(); // Ensure sequential execution
1442+
14381443
init_tracing_for_tests();
1439-
std::env::remove_var("RUST_LOG");
1440-
update_tracing(tracing::Level::TRACE);
1444+
update_tracing_log_level(tracing::Level::TRACE);
14411445

14421446
let output = capture_stderr(|| {
14431447
tracing::info!("Info message to stderr");
@@ -1461,10 +1465,12 @@ mod tracing_tests {
14611465

14621466
#[test]
14631467
fn test_update_tracing_respects_rust_log() {
1468+
let _lock = TEST_MUTEX.lock().unwrap(); // Ensure sequential execution
1469+
14641470
init_tracing_for_tests();
14651471
// Set RUST_LOG before initializing(not possible in this test) or after updating tracing
14661472
std::env::set_var("RUST_LOG", "info");
1467-
update_tracing(tracing::Level::DEBUG);
1473+
update_tracing_log_level(tracing::Level::DEBUG);
14681474

14691475
let output = capture_stderr(|| {
14701476
tracing::info!("Info message to stderr");
@@ -1479,5 +1485,7 @@ mod tracing_tests {
14791485
!output.contains("Debug message to stderr"),
14801486
"Expected DEBUG message found"
14811487
);
1488+
1489+
std::env::remove_var("RUST_LOG");
14821490
}
14831491
}

utils/src/tracing_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn initialize_tracing() {
4040
}
4141

4242
/// Update tracing log level dynamically.
43-
pub fn update_tracing(log_level: Level) {
43+
pub fn update_tracing_log_level(log_level: Level) {
4444
if let Some(handle) = TRACING_RELOAD_HANDLE.get() {
4545
// Create new filter. Use `RUST_LOG` if available
4646
let new_filter = EnvFilter::try_from_default_env()

0 commit comments

Comments
 (0)