1 | #![cfg (feature = "std" )] |
2 | |
3 | use tracing_mock::*; |
4 | |
5 | #[cfg_attr (target_arch = "wasm32" , wasm_bindgen_test::wasm_bindgen_test)] |
6 | #[test] |
7 | fn spans_dont_leak() { |
8 | fn do_span() { |
9 | let span = tracing::debug_span!("alice" ); |
10 | let _e = span.enter(); |
11 | } |
12 | |
13 | let (subscriber, handle) = subscriber::mock() |
14 | .named("spans/subscriber1" ) |
15 | .with_filter(|_| false) |
16 | .only() |
17 | .run_with_handle(); |
18 | |
19 | let _guard = tracing::subscriber::set_default(subscriber); |
20 | |
21 | do_span(); |
22 | |
23 | let alice = expect::span().named("alice" ); |
24 | let (subscriber2, handle2) = subscriber::mock() |
25 | .named("spans/subscriber2" ) |
26 | .with_filter(|_| true) |
27 | .new_span(alice.clone()) |
28 | .enter(alice.clone()) |
29 | .exit(alice.clone()) |
30 | .drop_span(alice) |
31 | .only() |
32 | .run_with_handle(); |
33 | |
34 | tracing::subscriber::with_default(subscriber2, || { |
35 | println!("--- subscriber 2 is default ---" ); |
36 | do_span() |
37 | }); |
38 | |
39 | println!("--- subscriber 1 is default ---" ); |
40 | do_span(); |
41 | |
42 | handle.assert_finished(); |
43 | handle2.assert_finished(); |
44 | } |
45 | |
46 | #[cfg_attr (target_arch = "wasm32" , wasm_bindgen_test::wasm_bindgen_test)] |
47 | #[test] |
48 | fn events_dont_leak() { |
49 | fn do_event() { |
50 | tracing::debug!("alice" ); |
51 | } |
52 | |
53 | let (subscriber, handle) = subscriber::mock() |
54 | .named("events/subscriber1" ) |
55 | .with_filter(|_| false) |
56 | .only() |
57 | .run_with_handle(); |
58 | |
59 | let _guard = tracing::subscriber::set_default(subscriber); |
60 | |
61 | do_event(); |
62 | |
63 | let (subscriber2, handle2) = subscriber::mock() |
64 | .named("events/subscriber2" ) |
65 | .with_filter(|_| true) |
66 | .event(expect::event()) |
67 | .only() |
68 | .run_with_handle(); |
69 | |
70 | tracing::subscriber::with_default(subscriber2, || { |
71 | println!("--- subscriber 2 is default ---" ); |
72 | do_event() |
73 | }); |
74 | |
75 | println!("--- subscriber 1 is default ---" ); |
76 | |
77 | do_event(); |
78 | |
79 | handle.assert_finished(); |
80 | handle2.assert_finished(); |
81 | } |
82 | |