Skip to content

Commit

Permalink
tests: add regression test for #6051
Browse files Browse the repository at this point in the history
  • Loading branch information
jswrenn committed Dec 6, 2023
1 parent a0a58d7 commit 84f8793
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tokio/tests/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,73 @@ mod future_completes_during_trace {
async fn dump() {
let handle = Handle::current();
let _dump = handle.dump().await;
tokio::task::yield_now().await;
}

rt.block_on(async {
let _ = tokio::join!(tokio::spawn(complete_during_trace()), dump());
});
}
}

/// Regression tests for #6051.
///
/// These tests ensure that tasks notified outside of a worker will not be
/// traced, since doing so will un-set their notified bit prior to them being
/// run and panic.
mod notified_during_tracing {
use super::*;

fn test(rt: tokio::runtime::Runtime) {
async fn dump() {
loop {
let handle = Handle::current();
let _dump = handle.dump().await;
// Without this yield, the `current_runtime` test hangs.
tokio::task::yield_now().await;
}
}

rt.block_on(async {
let timer = tokio::spawn(async {
loop {
tokio::time::sleep(tokio::time::Duration::from_nanos(1)).await;
}
});

let timeout = async {
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
};

tokio::select!(
biased;
_ = timeout => {},
_ = timer => {},
_ = dump() => {},
);
});
}

#[test]
// TODO: This currently hangs, with or without the regression fix. Adding a
// `yield_now` to the end of `fn dump()` above fixes the issue, but why?
fn current_thread() {
let rt = runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();

test(rt)
}

#[test]
fn multi_thread() {
let rt = runtime::Builder::new_multi_thread()
.enable_all()
.worker_threads(3)
.build()
.unwrap();

test(rt)
}
}

0 comments on commit 84f8793

Please sign in to comment.