1#![cfg(feature = "std")]
2use tracing_mock::*;
3
4#[test]
5fn scoped_clobbers_global() {
6 // Reproduces https://github.com/tokio-rs/tracing/issues/2050
7
8 let (scoped, scoped_handle) = subscriber::mock()
9 .event(event::msg("before global"))
10 .event(event::msg("before drop"))
11 .only()
12 .run_with_handle();
13
14 let (global, global_handle) = subscriber::mock()
15 .event(event::msg("after drop"))
16 .only()
17 .run_with_handle();
18
19 // Set a scoped default subscriber, returning a guard.
20 let guard = tracing::subscriber::set_default(scoped);
21 tracing::info!("before global");
22
23 // Now, set the global default.
24 tracing::subscriber::set_global_default(global)
25 .expect("global default should not already be set");
26 // This event should still be collected by the scoped default.
27 tracing::info!("before drop");
28
29 // Drop the guard. Now, the global default subscriber should be used.
30 drop(guard);
31 tracing::info!("after drop");
32
33 scoped_handle.assert_finished();
34 global_handle.assert_finished();
35}
36