From 8ba80ae82371638aa749436e4f284b65adf9ff90 Mon Sep 17 00:00:00 2001 From: Sleep_AllDay <37238439+SpeedReach@users.noreply.github.com> Date: Wed, 15 Nov 2023 02:08:35 +0800 Subject: [PATCH] subscriber: fix flaky reload tests 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. --- tracing-subscriber/tests/reload.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tracing-subscriber/tests/reload.rs b/tracing-subscriber/tests/reload.rs index 381a307c50..58b75c01fb 100644 --- a/tracing-subscriber/tests/reload.rs +++ b/tracing-subscriber/tests/reload.rs @@ -47,7 +47,15 @@ impl tracing_subscriber::Subscribe 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); @@ -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);