runtime: fix race in yield_defers_until_park test (#6809)

This commit is contained in:
Antonio de la Vega
2024-08-31 21:34:22 +02:00
committed by GitHub
parent ea6d652a10
commit 27539ae3bd
+9 -4
View File
@@ -785,9 +785,9 @@ rt_test! {
barrier.wait();
let (fail_test, fail_test_recv) = oneshot::channel::<()>();
let flag_clone = flag.clone();
let jh = tokio::spawn(async move {
// Create a TCP litener
// Create a TCP listener
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap();
@@ -798,7 +798,7 @@ rt_test! {
// Yield until connected
let mut cnt = 0;
while !flag.load(SeqCst){
while !flag_clone.load(SeqCst){
tokio::task::yield_now().await;
cnt += 1;
@@ -814,7 +814,7 @@ rt_test! {
},
async {
let _ = listener.accept().await.unwrap();
flag.store(true, SeqCst);
flag_clone.store(true, SeqCst);
}
);
});
@@ -824,6 +824,11 @@ rt_test! {
let success = fail_test_recv.await.is_err();
if success {
// Setting flag to true ensures that the tasks we spawned at
// the beginning of the test will exit.
// If we don't do this, the test will hang since the runtime waits
// for all spawned tasks to finish when dropping.
flag.store(true, SeqCst);
// Check for panics in spawned task.
jh.abort();
jh.await.unwrap();