Skip to content

Commit b5c227d

Browse files
authored
tracing: move tracing instrumentation tests into tokio tests (#7007)
In #6112, tests for the tracing instrumentation were introduced. They had to live in their own test crate under `tokio/tests` because the `tracing-mock` crate that the tests use had not yet been published to crates.io. Now `tracing-mock` has been published to crates.io and so the separate test crate and separate job to run it are no longer necessary. The tracing instrumentation tests can be placed in with the other integration tests in the `tokio` crate. The tests themselves have also been updated to match the changes in the `tracing-mock` API since the version which was being used.
1 parent dcae2b9 commit b5c227d

File tree

6 files changed

+104
-98
lines changed

6 files changed

+104
-98
lines changed

.github/workflows/ci.yml

-29
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ jobs:
4747
- test-workspace-all-features
4848
- test-integration-tests-per-feature
4949
- test-parking_lot
50-
- test-tracing-instrumentation
5150
- valgrind
5251
- test-unstable
5352
- miri
@@ -246,34 +245,6 @@ jobs:
246245
- name: Check tests with all features enabled
247246
run: cargo check --workspace --all-features --tests
248247

249-
test-tracing-instrumentation:
250-
# These tests use the as-yet unpublished `tracing-mock` crate to test the
251-
# tracing instrumentation present in Tokio. As such they are placed in
252-
# their own test crate outside of the workspace.
253-
needs: basics
254-
name: test tokio instrumentation
255-
runs-on: ubuntu-latest
256-
steps:
257-
- uses: actions/checkout@v4
258-
- name: Install Rust ${{ env.rust_stable }}
259-
uses: dtolnay/rust-toolchain@stable
260-
with:
261-
toolchain: ${{ env.rust_stable }}
262-
- name: Install cargo-nextest
263-
uses: taiki-e/install-action@v2
264-
with:
265-
tool: cargo-nextest
266-
267-
- uses: Swatinem/rust-cache@v2
268-
269-
- name: test tracing-instrumentation
270-
run: |
271-
set -euxo pipefail
272-
cargo nextest run
273-
working-directory: tokio/tests/tracing-instrumentation
274-
env:
275-
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
276-
277248
valgrind:
278249
name: valgrind
279250
needs: basics

tokio/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ mio-aio = { version = "0.9.0", features = ["tokio"] }
151151
[target.'cfg(loom)'.dev-dependencies]
152152
loom = { version = "0.7", features = ["futures", "checkpoint"] }
153153

154+
[target.'cfg(all(tokio_unstable, target_has_atomic = "64"))'.dev-dependencies]
155+
tracing-mock = "= 0.1.0-beta.1"
156+
154157
[package.metadata.docs.rs]
155158
all-features = true
156159
# enable unstable features in the documentation

tokio/tests/tracing-instrumentation/Cargo.toml

-17
This file was deleted.

tokio/tests/tracing-instrumentation/tests/sync.rs renamed to tokio/tests/tracing_sync.rs

+72-37
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
//!
33
//! These tests ensure that the instrumentation for tokio
44
//! synchronization primitives is correct.
5+
#![allow(unknown_lints, unexpected_cfgs)]
6+
#![warn(rust_2018_idioms)]
7+
#![cfg(all(tokio_unstable, feature = "tracing", target_has_atomic = "64"))]
58

69
use tokio::sync;
710
use tracing_mock::{expect, subscriber};
@@ -14,19 +17,23 @@ async fn test_barrier_creates_span() {
1417

1518
let size_event = expect::event()
1619
.with_target("runtime::resource::state_update")
17-
.with_fields(expect::field("size").with_value(&1u64));
20+
.with_fields(expect::field("size").with_value(&1_u64));
1821

1922
let arrived_event = expect::event()
2023
.with_target("runtime::resource::state_update")
21-
.with_fields(expect::field("arrived").with_value(&0));
24+
.with_fields(expect::field("arrived").with_value(&0_i64));
2225

2326
let (subscriber, handle) = subscriber::mock()
24-
.new_span(barrier_span.clone().with_explicit_parent(None))
25-
.enter(barrier_span.clone())
27+
.new_span(
28+
barrier_span
29+
.clone()
30+
.with_ancestry(expect::is_explicit_root()),
31+
)
32+
.enter(&barrier_span)
2633
.event(size_event)
2734
.event(arrived_event)
28-
.exit(barrier_span.clone())
29-
.drop_span(barrier_span)
35+
.exit(&barrier_span)
36+
.drop_span(&barrier_span)
3037
.run_with_handle();
3138

3239
{
@@ -57,16 +64,20 @@ async fn test_mutex_creates_span() {
5764
.with_fields(expect::field("permits.op").with_value(&"override"));
5865

5966
let (subscriber, handle) = subscriber::mock()
60-
.new_span(mutex_span.clone().with_explicit_parent(None))
61-
.enter(mutex_span.clone())
67+
.new_span(mutex_span.clone().with_ancestry(expect::is_explicit_root()))
68+
.enter(&mutex_span)
6269
.event(locked_event)
63-
.new_span(batch_semaphore_span.clone().with_explicit_parent(None))
64-
.enter(batch_semaphore_span.clone())
70+
.new_span(
71+
batch_semaphore_span
72+
.clone()
73+
.with_ancestry(expect::is_explicit_root()),
74+
)
75+
.enter(&batch_semaphore_span)
6576
.event(batch_semaphore_permits_event)
66-
.exit(batch_semaphore_span.clone())
67-
.exit(mutex_span.clone())
68-
.drop_span(mutex_span)
69-
.drop_span(batch_semaphore_span)
77+
.exit(&batch_semaphore_span)
78+
.exit(&mutex_span)
79+
.drop_span(&mutex_span)
80+
.drop_span(&batch_semaphore_span)
7081
.run_with_handle();
7182

7283
{
@@ -79,7 +90,9 @@ async fn test_mutex_creates_span() {
7990

8091
#[tokio::test]
8192
async fn test_oneshot_creates_span() {
93+
let oneshot_span_id = expect::id();
8294
let oneshot_span = expect::span()
95+
.with_id(oneshot_span_id.clone())
8396
.named("runtime.resource")
8497
.with_target("tokio::sync::oneshot");
8598

@@ -113,7 +126,9 @@ async fn test_oneshot_creates_span() {
113126
.with_fields(expect::field("value_received").with_value(&false))
114127
.with_fields(expect::field("value_received.op").with_value(&"override"));
115128

129+
let async_op_span_id = expect::id();
116130
let async_op_span = expect::span()
131+
.with_id(async_op_span_id.clone())
117132
.named("runtime.resource.async_op")
118133
.with_target("tokio::sync::oneshot");
119134

@@ -122,34 +137,46 @@ async fn test_oneshot_creates_span() {
122137
.with_target("tokio::sync::oneshot");
123138

124139
let (subscriber, handle) = subscriber::mock()
125-
.new_span(oneshot_span.clone().with_explicit_parent(None))
126-
.enter(oneshot_span.clone())
140+
.new_span(
141+
oneshot_span
142+
.clone()
143+
.with_ancestry(expect::is_explicit_root()),
144+
)
145+
.enter(&oneshot_span)
127146
.event(initial_tx_dropped_event)
128-
.exit(oneshot_span.clone())
129-
.enter(oneshot_span.clone())
147+
.exit(&oneshot_span)
148+
.enter(&oneshot_span)
130149
.event(initial_rx_dropped_event)
131-
.exit(oneshot_span.clone())
132-
.enter(oneshot_span.clone())
150+
.exit(&oneshot_span)
151+
.enter(&oneshot_span)
133152
.event(value_sent_event)
134-
.exit(oneshot_span.clone())
135-
.enter(oneshot_span.clone())
153+
.exit(&oneshot_span)
154+
.enter(&oneshot_span)
136155
.event(value_received_event)
137-
.exit(oneshot_span.clone())
138-
.enter(oneshot_span.clone())
139-
.new_span(async_op_span.clone())
140-
.exit(oneshot_span.clone())
141-
.enter(async_op_span.clone())
142-
.new_span(async_op_poll_span.clone())
143-
.exit(async_op_span.clone())
144-
.enter(oneshot_span.clone())
156+
.exit(&oneshot_span)
157+
.enter(&oneshot_span)
158+
.new_span(
159+
async_op_span
160+
.clone()
161+
.with_ancestry(expect::has_contextual_parent(&oneshot_span_id)),
162+
)
163+
.exit(&oneshot_span)
164+
.enter(&async_op_span)
165+
.new_span(
166+
async_op_poll_span
167+
.clone()
168+
.with_ancestry(expect::has_contextual_parent(&async_op_span_id)),
169+
)
170+
.exit(&async_op_span)
171+
.enter(&oneshot_span)
145172
.event(final_tx_dropped_event)
146-
.exit(oneshot_span.clone())
147-
.enter(oneshot_span.clone())
173+
.exit(&oneshot_span)
174+
.enter(&oneshot_span)
148175
.event(final_rx_dropped_event)
149-
.exit(oneshot_span.clone())
176+
.exit(&oneshot_span)
150177
.drop_span(oneshot_span)
151178
.drop_span(async_op_span)
152-
.drop_span(async_op_poll_span)
179+
.drop_span(&async_op_poll_span)
153180
.run_with_handle();
154181

155182
{
@@ -176,7 +203,7 @@ async fn test_rwlock_creates_span() {
176203

177204
let current_readers_event = expect::event()
178205
.with_target("runtime::resource::state_update")
179-
.with_fields(expect::field("current_readers").with_value(&0));
206+
.with_fields(expect::field("current_readers").with_value(&0_i64));
180207

181208
let batch_semaphore_span = expect::span()
182209
.named("runtime.resource")
@@ -188,7 +215,11 @@ async fn test_rwlock_creates_span() {
188215
.with_fields(expect::field("permits.op").with_value(&"override"));
189216

190217
let (subscriber, handle) = subscriber::mock()
191-
.new_span(rwlock_span.clone().with_explicit_parent(None))
218+
.new_span(
219+
rwlock_span
220+
.clone()
221+
.with_ancestry(expect::is_explicit_root()),
222+
)
192223
.enter(rwlock_span.clone())
193224
.event(max_readers_event)
194225
.event(write_locked_event)
@@ -228,7 +259,11 @@ async fn test_semaphore_creates_span() {
228259
.with_fields(expect::field("permits.op").with_value(&"override"));
229260

230261
let (subscriber, handle) = subscriber::mock()
231-
.new_span(semaphore_span.clone().with_explicit_parent(None))
262+
.new_span(
263+
semaphore_span
264+
.clone()
265+
.with_ancestry(expect::is_explicit_root()),
266+
)
232267
.enter(semaphore_span.clone())
233268
.new_span(batch_semaphore_span.clone())
234269
.enter(batch_semaphore_span.clone())

tokio/tests/tracing-instrumentation/tests/task.rs renamed to tokio/tests/tracing_task.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
//!
33
//! These tests ensure that the instrumentation for task spawning and task
44
//! lifecycles is correct.
5+
#![allow(unknown_lints, unexpected_cfgs)]
6+
#![warn(rust_2018_idioms)]
7+
#![cfg(all(tokio_unstable, feature = "tracing", target_has_atomic = "64"))]
58

69
use std::{mem, time::Duration};
710

@@ -15,12 +18,12 @@ async fn task_spawn_creates_span() {
1518
.with_target("tokio::task");
1619

1720
let (subscriber, handle) = subscriber::mock()
18-
.new_span(task_span.clone())
19-
.enter(task_span.clone())
20-
.exit(task_span.clone())
21+
.new_span(&task_span)
22+
.enter(&task_span)
23+
.exit(&task_span)
2124
// The task span is entered once more when it gets dropped
22-
.enter(task_span.clone())
23-
.exit(task_span.clone())
25+
.enter(&task_span)
26+
.exit(&task_span)
2427
.drop_span(task_span)
2528
.run_with_handle();
2629

@@ -39,7 +42,7 @@ async fn task_spawn_loc_file_recorded() {
3942
let task_span = expect::span()
4043
.named("runtime.spawn")
4144
.with_target("tokio::task")
42-
.with_field(expect::field("loc.file").with_value(&file!()));
45+
.with_fields(expect::field("loc.file").with_value(&file!()));
4346

4447
let (subscriber, handle) = subscriber::mock().new_span(task_span).run_with_handle();
4548

@@ -78,7 +81,7 @@ async fn task_builder_loc_file_recorded() {
7881
let task_span = expect::span()
7982
.named("runtime.spawn")
8083
.with_target("tokio::task")
81-
.with_field(expect::field("loc.file").with_value(&file!()));
84+
.with_fields(expect::field("loc.file").with_value(&file!()));
8285

8386
let (subscriber, handle) = subscriber::mock().new_span(task_span).run_with_handle();
8487

@@ -105,7 +108,7 @@ async fn task_spawn_sizes_recorded() {
105108
.with_target("tokio::task")
106109
// TODO(hds): check that original_size.bytes is NOT recorded when this can be done in
107110
// tracing-mock without listing every other field.
108-
.with_field(expect::field("size.bytes").with_value(&size));
111+
.with_fields(expect::field("size.bytes").with_value(&size));
109112

110113
let (subscriber, handle) = subscriber::mock().new_span(task_span).run_with_handle();
111114

@@ -149,7 +152,7 @@ async fn task_big_spawn_sizes_recorded() {
149152
let task_span = expect::span()
150153
.named("runtime.spawn")
151154
.with_target("tokio::task")
152-
.with_field(
155+
.with_fields(
153156
expect::field("size.bytes")
154157
.with_value(&boxed_size)
155158
.and(expect::field("original_size.bytes").with_value(&size)),
@@ -178,7 +181,7 @@ fn expect_task_named(name: &str) -> NewSpan {
178181
expect::span()
179182
.named("runtime.spawn")
180183
.with_target("tokio::task")
181-
.with_field(
184+
.with_fields(
182185
expect::field("task.name").with_value(&tracing::field::debug(format_args!("{}", name))),
183186
)
184187
}

tokio/tests/tracing-instrumentation/tests/time.rs renamed to tokio/tests/tracing_time.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,36 @@
22
//!
33
//! These tests ensure that the instrumentation for tokio
44
//! synchronization primitives is correct.
5+
#![allow(unknown_lints, unexpected_cfgs)]
6+
#![warn(rust_2018_idioms)]
7+
#![cfg(all(tokio_unstable, feature = "tracing", target_has_atomic = "64"))]
8+
59
use std::time::Duration;
610

711
use tracing_mock::{expect, subscriber};
812

913
#[tokio::test]
1014
async fn test_sleep_creates_span() {
15+
let sleep_span_id = expect::id();
1116
let sleep_span = expect::span()
17+
.with_id(sleep_span_id.clone())
1218
.named("runtime.resource")
1319
.with_target("tokio::time::sleep");
1420

1521
let state_update = expect::event()
1622
.with_target("runtime::resource::state_update")
1723
.with_fields(
1824
expect::field("duration")
19-
.with_value(&(7_u64 + 1))
25+
// FIXME(hds): This value isn't stable and doesn't seem to make sense. We're not
26+
// going to test on it until the resource instrumentation has been
27+
// refactored and we know that we're getting a stable value here.
28+
//.with_value(&(7_u64 + 1))
2029
.and(expect::field("duration.op").with_value(&"override")),
2130
);
2231

32+
let async_op_span_id = expect::id();
2333
let async_op_span = expect::span()
34+
.with_id(async_op_span_id.clone())
2435
.named("runtime.resource.async_op")
2536
.with_target("tokio::time::sleep");
2637

@@ -29,21 +40,21 @@ async fn test_sleep_creates_span() {
2940
.with_target("tokio::time::sleep");
3041

3142
let (subscriber, handle) = subscriber::mock()
32-
.new_span(sleep_span.clone().with_explicit_parent(None))
43+
.new_span(sleep_span.clone().with_ancestry(expect::is_explicit_root()))
3344
.enter(sleep_span.clone())
3445
.event(state_update)
3546
.new_span(
3647
async_op_span
3748
.clone()
38-
.with_contextual_parent(Some("runtime.resource"))
39-
.with_field(expect::field("source").with_value(&"Sleep::new_timeout")),
49+
.with_ancestry(expect::has_contextual_parent(&sleep_span_id))
50+
.with_fields(expect::field("source").with_value(&"Sleep::new_timeout")),
4051
)
4152
.exit(sleep_span.clone())
4253
.enter(async_op_span.clone())
4354
.new_span(
4455
async_op_poll_span
4556
.clone()
46-
.with_contextual_parent(Some("runtime.resource.async_op")),
57+
.with_ancestry(expect::has_contextual_parent(&async_op_span_id)),
4758
)
4859
.exit(async_op_span.clone())
4960
.drop_span(async_op_span)

0 commit comments

Comments
 (0)