-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
mod common; | ||
|
||
use common::*; | ||
use tracing_core::{subscriber::NoSubscriber, dispatcher::{Dispatch, self}}; | ||
|
||
/// This test reproduces the following issues: | ||
/// - https://github.com/tokio-rs/tracing/issues/2587 | ||
/// - https://github.com/tokio-rs/tracing/issues/2411 | ||
/// - https://github.com/tokio-rs/tracing/issues/2436 | ||
#[test] | ||
fn local_dispatch_before_init() { | ||
dispatcher::get_default(|current| assert!(current.is::<NoSubscriber>())); | ||
|
||
// Temporarily override the default dispatcher with a scoped dispatcher. | ||
// | ||
// This will suppress the "SCOPED_COUNT" optimization and cause threads to | ||
// attempt to cache the global default after the scoped dispatcher has been | ||
// unset. | ||
#[cfg(feature = "std")] { | ||
dispatcher::with_default(&Dispatch::new(TestSubscriberB), || { | ||
dispatcher::get_default(|current| { | ||
assert!( | ||
current.is::<TestSubscriberB>(), | ||
"overriden subscriber not set; current: {:?}", | ||
current, | ||
); | ||
}) | ||
}) | ||
} | ||
|
||
dispatcher::get_default(|current| assert!(current.is::<NoSubscriber>())); | ||
|
||
dispatcher::set_global_default(Dispatch::new(TestSubscriberA)) | ||
.expect("set global dispatch failed"); | ||
|
||
dispatcher::get_default(|current| { | ||
assert!( | ||
current.is::<TestSubscriberA>(), | ||
"default subscriber not set; current: {:?}", | ||
current, | ||
); | ||
}); | ||
|
||
} |