summaryrefslogtreecommitdiffstats
path: root/third_party/rust/tracing/tests/register_callsite_deadlock.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/tracing/tests/register_callsite_deadlock.rs
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/tracing/tests/register_callsite_deadlock.rs')
-rw-r--r--third_party/rust/tracing/tests/register_callsite_deadlock.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/third_party/rust/tracing/tests/register_callsite_deadlock.rs b/third_party/rust/tracing/tests/register_callsite_deadlock.rs
new file mode 100644
index 0000000000..e4c116c75f
--- /dev/null
+++ b/third_party/rust/tracing/tests/register_callsite_deadlock.rs
@@ -0,0 +1,47 @@
+use std::{sync::mpsc, thread, time::Duration};
+use tracing::{
+ metadata::Metadata,
+ span,
+ subscriber::{self, Interest, Subscriber},
+ Event,
+};
+
+#[test]
+fn register_callsite_doesnt_deadlock() {
+ pub struct EvilSubscriber;
+
+ impl Subscriber for EvilSubscriber {
+ fn register_callsite(&self, meta: &'static Metadata<'static>) -> Interest {
+ tracing::info!(?meta, "registered a callsite");
+ Interest::always()
+ }
+
+ fn enabled(&self, _: &Metadata<'_>) -> bool {
+ true
+ }
+ fn new_span(&self, _: &span::Attributes<'_>) -> span::Id {
+ span::Id::from_u64(1)
+ }
+ fn record(&self, _: &span::Id, _: &span::Record<'_>) {}
+ fn record_follows_from(&self, _: &span::Id, _: &span::Id) {}
+ fn event(&self, _: &Event<'_>) {}
+ fn enter(&self, _: &span::Id) {}
+ fn exit(&self, _: &span::Id) {}
+ }
+
+ subscriber::set_global_default(EvilSubscriber).unwrap();
+
+ // spawn a thread, and assert it doesn't hang...
+ let (tx, didnt_hang) = mpsc::channel();
+ let th = thread::spawn(move || {
+ tracing::info!("hello world!");
+ tx.send(()).unwrap();
+ });
+
+ didnt_hang
+ // Note: 60 seconds is *way* more than enough, but let's be generous in
+ // case of e.g. slow CI machines.
+ .recv_timeout(Duration::from_secs(60))
+ .expect("the thread must not have hung!");
+ th.join().expect("thread should join successfully");
+}