Skip to content

Commit e4ee3a5

Browse files
brian030128hds
authored andcommitted
subscriber: fix flaky reload tests (#2798)
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 96c0e29 commit e4ee3a5

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
@@ -32,7 +32,15 @@ impl Subscriber for NopSubscriber {
3232
fn exit(&self, _: &Id) {}
3333
}
3434

35+
/// Running these two tests in parallel will cause flaky failures, since they are both modifying the MAX_LEVEL value.
36+
/// "cargo test -- --test-threads=1 fixes it, but it runs all tests in serial.
37+
/// The only way to run tests in serial in a single file is this way.
3538
#[test]
39+
fn run_all_reload_test() {
40+
reload_handle();
41+
reload_filter();
42+
}
43+
3644
fn reload_handle() {
3745
static FILTER1_CALLS: AtomicUsize = AtomicUsize::new(0);
3846
static FILTER2_CALLS: AtomicUsize = AtomicUsize::new(0);
@@ -89,7 +97,6 @@ fn reload_handle() {
8997
})
9098
}
9199

92-
#[test]
93100
fn reload_filter() {
94101
struct NopLayer;
95102
impl<S: Subscriber> tracing_subscriber::Layer<S> for NopLayer {

0 commit comments

Comments
 (0)