Skip to content

Commit

Permalink
rt: improve robustness of wake_in_drop_after_panic test (#6238)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn authored Jan 2, 2024
1 parent c029771 commit 2d2faf6
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions tokio/tests/rt_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,35 @@ fn drop_tasks_in_context() {
#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")]
#[should_panic(expected = "boom")]
fn wake_in_drop_after_panic() {
let (tx, rx) = oneshot::channel::<()>();

struct WakeOnDrop(Option<oneshot::Sender<()>>);

impl Drop for WakeOnDrop {
fn drop(&mut self) {
self.0.take().unwrap().send(()).unwrap();
let _ = self.0.take().unwrap().send(());
}
}

let rt = rt();

let (tx1, rx1) = oneshot::channel::<()>();
let (tx2, rx2) = oneshot::channel::<()>();

// Spawn two tasks. We don't know the order in which they are dropped, so we
// make both tasks identical. When the first task is dropped, we wake up the
// second task. This ensures that we trigger a wakeup on a live task while
// handling the "boom" panic, no matter the order in which the tasks are
// dropped.
rt.spawn(async move {
let _wake_on_drop = WakeOnDrop(Some(tx));
// wait forever
futures::future::pending::<()>().await;
let _wake_on_drop = WakeOnDrop(Some(tx2));
let _ = rx1.await;
unreachable!()
});

let _join = rt.spawn(async move { rx.await });
rt.spawn(async move {
let _wake_on_drop = WakeOnDrop(Some(tx1));
let _ = rx2.await;
unreachable!()
});

rt.block_on(async {
tokio::task::yield_now().await;
Expand Down

0 comments on commit 2d2faf6

Please sign in to comment.