Skip to content

Commit

Permalink
tests: add regression test for tokio-rs#6051
Browse files Browse the repository at this point in the history
  • Loading branch information
jswrenn committed Dec 6, 2023
1 parent a0a58d7 commit 7ae7347
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tokio/tests/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,71 @@ 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]
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 7ae7347

Please sign in to comment.