use std::sync::Arc;
use tracing_calltree::CallTree;
use tracing_subscriber::prelude::*;
#[test]
fn concurrent_recording_and_snapshotting_stays_bounded() {
let calltree = Arc::new(CallTree::builder().window_size(50).build());
let subscriber = tracing_subscriber::registry().with(calltree.layer());
let dispatcher = Arc::new(tracing::Dispatch::new(subscriber));
std::thread::scope(|scope| {
for _ in 0..4 {
let dispatcher = dispatcher.clone();
scope.spawn(move || {
tracing::dispatcher::with_default(&dispatcher, || {
for _ in 0..200 {
tracing::info_span!("shared").in_scope(|| {});
}
});
});
}
for _ in 0..20 {
let snapshot = calltree.snapshot();
if let Some(node) = snapshot.roots.first() {
assert!(node.wall.samples <= 50);
}
}
});
let snapshot = calltree.snapshot();
let node = &snapshot.roots[0];
assert_eq!(node.total_calls, 800);
assert_eq!(node.wall.samples, 50);
}