Skip to content

Commit

Permalink
subscriber: fix flaky reload tests
Browse files Browse the repository at this point in the history
fixes https://github.com/tokio-rs/tracing/actions/runs/6785393202/job/18443641813

cargo test runs tests in the same file in parallel by default, causing race condition,
this can be proven by running 
`cargo test --test reload -- --test-threads=1` => successes 
`cargo test --test reload -- --test-threads=2` => flaky
multiple times 

This fix runs only the two tests in serial.
We could seperate the tests in different files, but they share the same testing dependencies, so I left them in the same file.
  • Loading branch information
SpeedReach authored Nov 14, 2023
1 parent 29c494d commit 8ba80ae
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tracing-subscriber/tests/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ impl<S: Collect> tracing_subscriber::Subscribe<S> for NopSubscriber {
}
}

/// Running these two tests in parallel will cause flaky failures, since they are both modifying the MAX_LEVEL value.
/// "cargo test -- --test-threads=1 fixes it, but it runs all tests in serial.
/// The only way to run tests in serial in a single file is this way.
#[test]
fn run_all_reload_test() {
reload_handle();
reload_filter();
}

fn reload_handle() {
static FILTER1_CALLS: AtomicUsize = AtomicUsize::new(0);
static FILTER2_CALLS: AtomicUsize = AtomicUsize::new(0);
Expand Down Expand Up @@ -104,7 +112,6 @@ fn reload_handle() {
})
}

#[test]
fn reload_filter() {
static FILTER1_CALLS: AtomicUsize = AtomicUsize::new(0);
static FILTER2_CALLS: AtomicUsize = AtomicUsize::new(0);
Expand Down

0 comments on commit 8ba80ae

Please sign in to comment.