Skip to content

Commit 7ae7347

Browse files
committed
tests: add regression test for #6051
1 parent a0a58d7 commit 7ae7347

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

tokio/tests/dump.rs

+61
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,71 @@ mod future_completes_during_trace {
147147
async fn dump() {
148148
let handle = Handle::current();
149149
let _dump = handle.dump().await;
150+
tokio::task::yield_now().await;
150151
}
151152

152153
rt.block_on(async {
153154
let _ = tokio::join!(tokio::spawn(complete_during_trace()), dump());
154155
});
155156
}
156157
}
158+
159+
/// Regression tests for #6051.
160+
///
161+
/// These tests ensure that tasks notified outside of a worker will not be
162+
/// traced, since doing so will un-set their notified bit prior to them being
163+
/// run and panic.
164+
mod notified_during_tracing {
165+
use super::*;
166+
167+
fn test(rt: tokio::runtime::Runtime) {
168+
async fn dump() {
169+
loop {
170+
let handle = Handle::current();
171+
let _dump = handle.dump().await;
172+
// Without this yield, the `current_runtime` test hangs.
173+
tokio::task::yield_now().await;
174+
}
175+
}
176+
177+
rt.block_on(async {
178+
let timer = tokio::spawn(async {
179+
loop {
180+
tokio::time::sleep(tokio::time::Duration::from_nanos(1)).await;
181+
}
182+
});
183+
184+
let timeout = async {
185+
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
186+
};
187+
188+
tokio::select!(
189+
biased;
190+
_ = timeout => {},
191+
_ = timer => {},
192+
_ = dump() => {},
193+
);
194+
});
195+
}
196+
197+
#[test]
198+
fn current_thread() {
199+
let rt = runtime::Builder::new_current_thread()
200+
.enable_all()
201+
.build()
202+
.unwrap();
203+
204+
test(rt)
205+
}
206+
207+
#[test]
208+
fn multi_thread() {
209+
let rt = runtime::Builder::new_multi_thread()
210+
.enable_all()
211+
.worker_threads(3)
212+
.build()
213+
.unwrap();
214+
215+
test(rt)
216+
}
217+
}

0 commit comments

Comments
 (0)