Skip to content

Commit 0fee376

Browse files
karthiknadigCopilot
andcommitted
test: prove lease retry after observed contention (Refs #529)
Release the independent holder only after the same polling invocation observes WouldBlock, and assert exactly two real lock attempts. This removes scheduling assumptions and rejects an immediate-timeout mutation without changing shutdown semantics. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 22a0e93 commit 0fee376

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

‎crates/pet/tests/jsonrpc_server_test.rs‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,13 @@ fn stdin_eof_exits_while_output_is_not_drained() {
676676
reader.join().unwrap();
677677
}
678678

679-
fn wait_for_descendant_lease(lease: &fs::File, timeout: Duration) -> std::io::Result<()> {
679+
fn wait_for_descendant_lease(
680+
mut try_lock: impl FnMut() -> Result<(), fs::TryLockError>,
681+
timeout: Duration,
682+
) -> std::io::Result<()> {
680683
let started = Instant::now();
681684
loop {
682-
match lease.try_lock() {
685+
match try_lock() {
683686
Ok(()) => return Ok(()),
684687
Err(fs::TryLockError::Error(error)) => return Err(error),
685688
Err(fs::TryLockError::WouldBlock) => {}
@@ -708,14 +711,28 @@ fn descendant_lease_wait_is_bounded_and_requires_release() {
708711
.unwrap();
709712
let started = Instant::now();
710713
assert_eq!(
711-
wait_for_descendant_lease(&lease, Duration::from_millis(20))
714+
wait_for_descendant_lease(|| lease.try_lock(), Duration::from_millis(20))
712715
.unwrap_err()
713716
.kind(),
714717
std::io::ErrorKind::TimedOut
715718
);
716719
assert!(started.elapsed() < Duration::from_secs(1));
717-
drop(holder);
718-
wait_for_descendant_lease(&lease, Duration::ZERO).unwrap();
720+
let mut holder = Some(holder);
721+
let mut attempts = 0;
722+
wait_for_descendant_lease(
723+
|| {
724+
attempts += 1;
725+
let result = lease.try_lock();
726+
if attempts == 1 {
727+
assert!(matches!(result, Err(fs::TryLockError::WouldBlock)));
728+
drop(holder.take());
729+
}
730+
result
731+
},
732+
Duration::from_secs(1),
733+
)
734+
.expect("lease polling must observe release after initial contention");
735+
assert_eq!(attempts, 2);
719736
}
720737

721738
#[cfg(feature = "ci")]
@@ -785,7 +802,7 @@ fn stdin_eof_cancels_an_active_interpreter_and_its_descendant() {
785802
);
786803
// Observe OS lease release within the same budget as server shutdown.
787804
wait_for_descendant_lease(
788-
&lease,
805+
|| lease.try_lock(),
789806
Duration::from_secs(4).saturating_sub(started.elapsed()),
790807
)
791808
.expect("shutdown must release the actual descendant's lease");

0 commit comments

Comments
 (0)