mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-10-02 15:24:47 +00:00

... instead of `#[path = ""]` importing it everywhere.
Make sure to use a diff review tool that understands file renaming 😅
(GitHub's diff view does.)
## Motivation
Transparency: I want to use the mocking functionality in the development
of a tracing component out-of-tree.
Additionally, this reduces the use of `#[path] mod` and file
multiple-inclusion, which aren't that great of a practice.
## Solution
The tracing test support module was already well self-contained, due to
being `#[path] mod` used in multiple places. As such, extracting it to
its own crate is rather mechanical, with no surprising blockers.
We additionally move the tracing-futures support module contents into
tracing_mock, for convenience. The one function which relies on
tokio-test is made optional.
It's a reasonable result for this functionality to stay unpublished, and
only used inside the repo, but pulling it out into a directly reusable
chunk instead of abusing the module system to reuse it via
multiple-inclusion is an improvement to code structure and
modularization.
48 lines
1.6 KiB
Rust
48 lines
1.6 KiB
Rust
#![cfg(all(feature = "env-filter", feature = "fmt"))]
|
|
use tracing::{self, subscriber::with_default, Span};
|
|
use tracing_subscriber::{filter::EnvFilter, FmtSubscriber};
|
|
|
|
#[test]
|
|
fn duplicate_spans() {
|
|
let subscriber = FmtSubscriber::builder()
|
|
.with_env_filter(EnvFilter::new("[root]=debug"))
|
|
.finish();
|
|
|
|
with_default(subscriber, || {
|
|
let root = tracing::debug_span!("root");
|
|
root.in_scope(|| {
|
|
// root:
|
|
assert_eq!(root, Span::current(), "Current span must be 'root'");
|
|
let leaf = tracing::debug_span!("leaf");
|
|
leaf.in_scope(|| {
|
|
// root:leaf:
|
|
assert_eq!(leaf, Span::current(), "Current span must be 'leaf'");
|
|
root.in_scope(|| {
|
|
// root:leaf:
|
|
assert_eq!(
|
|
leaf,
|
|
Span::current(),
|
|
"Current span must be 'leaf' after entering twice the 'root' span"
|
|
);
|
|
})
|
|
});
|
|
// root:
|
|
assert_eq!(
|
|
root,
|
|
Span::current(),
|
|
"Current span must be root ('leaf' exited, nested 'root' exited)"
|
|
);
|
|
|
|
root.in_scope(|| {
|
|
assert_eq!(root, Span::current(), "Current span must be root");
|
|
});
|
|
// root:
|
|
assert_eq!(
|
|
root,
|
|
Span::current(),
|
|
"Current span must still be root after exiting nested 'root'"
|
|
);
|
|
});
|
|
});
|
|
}
|