Skip to content

Commit

Permalink
runtime: fix race in yield_defers_until_park test (#6809)
Browse files Browse the repository at this point in the history
  • Loading branch information
adelavegaf committed Aug 31, 2024
1 parent ea6d652 commit 27539ae
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tokio/tests/rt_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;

Expand All @@ -814,7 +814,7 @@ rt_test! {
},
async {
let _ = listener.accept().await.unwrap();
flag.store(true, SeqCst);
flag_clone.store(true, SeqCst);
}
);
});
Expand All @@ -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();
Expand Down

0 comments on commit 27539ae

Please sign in to comment.