mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-17 00:00:11 +02:00
runtime: fix race in yield_defers_until_park test (#6809)
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user