From 6edf0029e96653fb390510171d523dc9e3de58a2 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Tue, 21 Oct 2025 11:27:46 -0700 Subject: [PATCH] test(semaphroe): try to make release more realistic --- tokio/src/sync/tests/loom_semaphore_batch.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tokio/src/sync/tests/loom_semaphore_batch.rs b/tokio/src/sync/tests/loom_semaphore_batch.rs index c1151fa13..f56df0c1b 100644 --- a/tokio/src/sync/tests/loom_semaphore_batch.rs +++ b/tokio/src/sync/tests/loom_semaphore_batch.rs @@ -58,21 +58,25 @@ fn cap_one() { async fn actor(shared: Arc, n: usize) { use futures::FutureExt; let mut the_acquire = Some(Box::pin(shared.semaphore.acquire(1))); + let mut should_release = true; poll_fn(|cx| match the_acquire.take() { Some(mut acquire) => match acquire.poll_unpin(cx) { - Poll::Ready(Ok(_)) => Poll::Ready(()), - Poll::Ready(Err(_)) => Poll::Ready(()), + Poll::Ready(Ok(_)) | Poll::Ready(Err(_)) => Poll::Ready(()), Poll::Pending if n % 2 == 0 => { the_acquire = Some(acquire); Poll::Pending } - Poll::Pending => Poll::Pending, + Poll::Pending => { + should_release = false; + Poll::Pending + } }, None => Poll::Ready(()), }) .await; - - shared.semaphore.release(1); + if should_release { + shared.semaphore.release(1); + } } static ITERS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);