summaryrefslogtreecommitdiffstats
path: root/third_party/rust/tracing-attributes/tests/follows_from.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-attributes/tests/follows_from.rs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/tracing-attributes/tests/follows_from.rs')
-rw-r--r--third_party/rust/tracing-attributes/tests/follows_from.rs99
1 files changed, 99 insertions, 0 deletions
diff --git a/third_party/rust/tracing-attributes/tests/follows_from.rs b/third_party/rust/tracing-attributes/tests/follows_from.rs
new file mode 100644
index 0000000000..da0eec6357
--- /dev/null
+++ b/third_party/rust/tracing-attributes/tests/follows_from.rs
@@ -0,0 +1,99 @@
+use tracing::{subscriber::with_default, Id, Level, Span};
+use tracing_attributes::instrument;
+use tracing_mock::*;
+
+#[instrument(follows_from = causes, skip(causes))]
+fn with_follows_from_sync(causes: impl IntoIterator<Item = impl Into<Option<Id>>>) {}
+
+#[instrument(follows_from = causes, skip(causes))]
+async fn with_follows_from_async(causes: impl IntoIterator<Item = impl Into<Option<Id>>>) {}
+
+#[instrument(follows_from = [&Span::current()])]
+fn follows_from_current() {}
+
+#[test]
+fn follows_from_sync_test() {
+ let cause_a = span::mock().named("cause_a");
+ let cause_b = span::mock().named("cause_b");
+ let cause_c = span::mock().named("cause_c");
+ let consequence = span::mock().named("with_follows_from_sync");
+
+ let (subscriber, handle) = subscriber::mock()
+ .new_span(cause_a.clone())
+ .new_span(cause_b.clone())
+ .new_span(cause_c.clone())
+ .new_span(consequence.clone())
+ .follows_from(consequence.clone(), cause_a)
+ .follows_from(consequence.clone(), cause_b)
+ .follows_from(consequence.clone(), cause_c)
+ .enter(consequence.clone())
+ .exit(consequence)
+ .done()
+ .run_with_handle();
+
+ with_default(subscriber, || {
+ let cause_a = tracing::span!(Level::TRACE, "cause_a");
+ let cause_b = tracing::span!(Level::TRACE, "cause_b");
+ let cause_c = tracing::span!(Level::TRACE, "cause_c");
+
+ with_follows_from_sync(&[cause_a, cause_b, cause_c])
+ });
+
+ handle.assert_finished();
+}
+
+#[test]
+fn follows_from_async_test() {
+ let cause_a = span::mock().named("cause_a");
+ let cause_b = span::mock().named("cause_b");
+ let cause_c = span::mock().named("cause_c");
+ let consequence = span::mock().named("with_follows_from_async");
+
+ let (subscriber, handle) = subscriber::mock()
+ .new_span(cause_a.clone())
+ .new_span(cause_b.clone())
+ .new_span(cause_c.clone())
+ .new_span(consequence.clone())
+ .follows_from(consequence.clone(), cause_a)
+ .follows_from(consequence.clone(), cause_b)
+ .follows_from(consequence.clone(), cause_c)
+ .enter(consequence.clone())
+ .exit(consequence)
+ .done()
+ .run_with_handle();
+
+ with_default(subscriber, || {
+ block_on_future(async {
+ let cause_a = tracing::span!(Level::TRACE, "cause_a");
+ let cause_b = tracing::span!(Level::TRACE, "cause_b");
+ let cause_c = tracing::span!(Level::TRACE, "cause_c");
+
+ with_follows_from_async(&[cause_a, cause_b, cause_c]).await
+ })
+ });
+
+ handle.assert_finished();
+}
+
+#[test]
+fn follows_from_current_test() {
+ let cause = span::mock().named("cause");
+ let consequence = span::mock().named("follows_from_current");
+
+ let (subscriber, handle) = subscriber::mock()
+ .new_span(cause.clone())
+ .enter(cause.clone())
+ .new_span(consequence.clone())
+ .follows_from(consequence.clone(), cause.clone())
+ .enter(consequence.clone())
+ .exit(consequence)
+ .exit(cause)
+ .done()
+ .run_with_handle();
+
+ with_default(subscriber, || {
+ tracing::span!(Level::TRACE, "cause").in_scope(follows_from_current)
+ });
+
+ handle.assert_finished();
+}