rt: fix flaky wake_while_rt_is_dropping test (#4698)

This commit is contained in:
Alice Ryhl
2022-05-17 19:20:34 +02:00
committed by GitHub
parent 052355f064
commit ddf2f5fdf6
+11 -8
View File
@@ -748,7 +748,7 @@ rt_test! {
#[test] #[test]
fn wake_while_rt_is_dropping() { fn wake_while_rt_is_dropping() {
use tokio::task; use tokio::sync::Barrier;
use core::sync::atomic::{AtomicBool, Ordering}; use core::sync::atomic::{AtomicBool, Ordering};
let drop_triggered = Arc::new(AtomicBool::new(false)); let drop_triggered = Arc::new(AtomicBool::new(false));
@@ -766,11 +766,16 @@ rt_test! {
let (tx2, rx2) = oneshot::channel(); let (tx2, rx2) = oneshot::channel();
let (tx3, rx3) = oneshot::channel(); let (tx3, rx3) = oneshot::channel();
let barrier = Arc::new(Barrier::new(4));
let barrier1 = barrier.clone();
let barrier2 = barrier.clone();
let barrier3 = barrier.clone();
let rt = rt(); let rt = rt();
rt.spawn(async move { rt.spawn(async move {
// Ensure a waker gets stored in oneshot 1. // Ensure a waker gets stored in oneshot 1.
let _ = rx1.await; let _ = tokio::join!(rx1, barrier1.wait());
tx3.send(()).unwrap(); tx3.send(()).unwrap();
}); });
@@ -791,20 +796,18 @@ rt_test! {
// Just a sanity check that this entire thing actually happened // Just a sanity check that this entire thing actually happened
set_drop_triggered.store(true, Ordering::Relaxed); set_drop_triggered.store(true, Ordering::Relaxed);
}); });
let _ = rx2.await; let _ = tokio::join!(rx2, barrier2.wait());
}); });
rt.spawn(async move { rt.spawn(async move {
let _ = rx3.await; let _ = tokio::join!(rx3, barrier3.wait());
// We'll never get here, but once task 3 drops, this will // We'll never get here, but once task 3 drops, this will
// force task 2 to re-schedule since it's waiting on oneshot 2. // force task 2 to re-schedule since it's waiting on oneshot 2.
tx2.send(()).unwrap(); tx2.send(()).unwrap();
}); });
// Tick the loop // Wait until every oneshot channel has been polled.
rt.block_on(async { rt.block_on(barrier.wait());
task::yield_now().await;
});
// Drop the rt // Drop the rt
drop(rt); drop(rt);