Skip to content

Commit

Permalink
subscriber: fix flaky reload tests (#2798)
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 and hds committed Nov 22, 2024
1 parent 96c0e29 commit e8c51f6
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 @@ -32,7 +32,15 @@ impl Subscriber for NopSubscriber {
fn exit(&self, _: &Id) {}
}

/// 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 @@ -89,7 +97,6 @@ fn reload_handle() {
})
}

#[test]
fn reload_filter() {
struct NopLayer;
impl<S: Subscriber> tracing_subscriber::Layer<S> for NopLayer {
Expand Down

0 comments on commit e8c51f6

Please sign in to comment.