Skip to content

Commit 8ba80ae

Browse files
authored
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.
1 parent 29c494d commit 8ba80ae

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tracing-subscriber/tests/reload.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ impl<S: Collect> tracing_subscriber::Subscribe<S> for NopSubscriber {
4747
}
4848
}
4949

50+
/// Running these two tests in parallel will cause flaky failures, since they are both modifying the MAX_LEVEL value.
51+
/// "cargo test -- --test-threads=1 fixes it, but it runs all tests in serial.
52+
/// The only way to run tests in serial in a single file is this way.
5053
#[test]
54+
fn run_all_reload_test() {
55+
reload_handle();
56+
reload_filter();
57+
}
58+
5159
fn reload_handle() {
5260
static FILTER1_CALLS: AtomicUsize = AtomicUsize::new(0);
5361
static FILTER2_CALLS: AtomicUsize = AtomicUsize::new(0);
@@ -104,7 +112,6 @@ fn reload_handle() {
104112
})
105113
}
106114

107-
#[test]
108115
fn reload_filter() {
109116
static FILTER1_CALLS: AtomicUsize = AtomicUsize::new(0);
110117
static FILTER2_CALLS: AtomicUsize = AtomicUsize::new(0);

0 commit comments

Comments
 (0)