Base: codex-main originale (prima del fork aKode)
This commit is contained in:
32
codex-rs/rollout/src/maintenance_tests.rs
Normal file
32
codex-rs/rollout/src/maintenance_tests.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
//! Tests maintenance ownership across shared guards and duplicated file handles.
|
||||
|
||||
use std::io;
|
||||
use std::sync::Arc;
|
||||
|
||||
use tempfile::TempDir;
|
||||
|
||||
use super::try_acquire_rollout_maintenance_lock;
|
||||
|
||||
#[test]
|
||||
fn dropping_last_guard_releases_lock_with_duplicated_handle() -> io::Result<()> {
|
||||
let home = TempDir::new()?;
|
||||
let guard = Arc::new(
|
||||
try_acquire_rollout_maintenance_lock(home.path())?.expect("acquire maintenance lock"),
|
||||
);
|
||||
let retained_guard = Arc::clone(&guard);
|
||||
let duplicated_file = guard.file.try_clone()?;
|
||||
|
||||
assert!(try_acquire_rollout_maintenance_lock(home.path())?.is_none());
|
||||
drop(guard);
|
||||
assert!(try_acquire_rollout_maintenance_lock(home.path())?.is_none());
|
||||
|
||||
drop(retained_guard);
|
||||
let next_guard = try_acquire_rollout_maintenance_lock(home.path())?
|
||||
.expect("dropping the last guard releases the lock despite the duplicated handle");
|
||||
|
||||
drop(duplicated_file);
|
||||
assert!(try_acquire_rollout_maintenance_lock(home.path())?.is_none());
|
||||
drop(next_guard);
|
||||
assert!(try_acquire_rollout_maintenance_lock(home.path())?.is_some());
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user