diff --git a/rust/Cargo.lock b/rust/Cargo.lock index ce9f66ccfc260..47a69d5902003 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -735,16 +735,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fs2" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "fs_extra" version = "1.3.0" @@ -2007,7 +1997,6 @@ dependencies = [ "env_logger", "exitcode", "flate2", - "fs2", "fs_extra", "infer 0.22.0", "is_executable", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index e4b165e2cfabc..5ff0f7d0b4983 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -2,6 +2,7 @@ name = "selenium-manager" version = "0.4.52-nightly" # don't forget to update rust/BUILD.bazel edition = "2024" +rust-version = "1.89" authors = ["Selenium > = const { RefCell::new(None) }); @@ -52,7 +51,7 @@ impl Lock { let file = File::create(&path)?; log.debug(format!("Acquiring lock: {}", path.display())); - file.lock_exclusive().unwrap_or_default(); + file.lock().unwrap_or_default(); set_lock_path(Some(path.to_path_buf())); Ok(Self { @@ -63,7 +62,7 @@ impl Lock { pub fn release(&mut self) { if let Some(file) = self.file.take() { - FileExt::unlock(&file).unwrap_or_default(); + file.unlock().unwrap_or_default(); fs::remove_file(&self.path).unwrap_or_default(); } set_lock_path(None); @@ -104,7 +103,7 @@ mod tests { use crate::logger::Logger; use std::fs; use std::path::PathBuf; - use std::time::{SystemTime, UNIX_EPOCH}; + use std::time::{Duration, SystemTime, UNIX_EPOCH}; fn create_test_dir(prefix: &str) -> PathBuf { let unique = SystemTime::now() @@ -148,4 +147,37 @@ mod tests { assert!(!lock_path.exists()); fs::remove_dir_all(root).unwrap(); } + + #[test] + fn acquire_blocks_until_lock_is_released() { + let root = create_test_dir("lock_blocked"); + let logger = Logger::new(); + let mut lock = Lock::acquire(&logger, &root, None).unwrap(); + + let (ready_tx, ready_rx) = std::sync::mpsc::channel(); + let (acquired_tx, acquired_rx) = std::sync::mpsc::channel(); + let root_clone = root.clone(); + let handle = std::thread::spawn(move || { + let logger = Logger::new(); + ready_tx.send(()).unwrap(); + let _competing = Lock::acquire(&logger, &root_clone, None).unwrap(); + acquired_tx.send(()).unwrap(); + }); + + ready_rx.recv().unwrap(); + assert!( + acquired_rx + .recv_timeout(Duration::from_millis(200)) + .is_err(), + "competing acquisition must remain blocked while the lock is held" + ); + + lock.release(); + acquired_rx + .recv_timeout(Duration::from_secs(5)) + .expect("competing acquisition must succeed after the lock is released"); + handle.join().unwrap(); + + fs::remove_dir_all(root).unwrap(); + } }