Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub trait SeleniumManager {
&driver_path_in_cache,
Some(driver_name_with_extension.clone()),
)?;
if !lock.exists() && driver_path_in_cache.exists() {
if driver_path_in_cache.exists() {
self.get_logger().debug(format!(
"Driver already in cache: {}",
driver_path_in_cache.display()
Expand Down Expand Up @@ -353,9 +353,8 @@ pub trait SeleniumManager {

let browser_path_in_cache = self.get_browser_path_in_cache()?;
let mut lock = Lock::acquire(self.get_logger(), &browser_path_in_cache, None)?;
// If lock file was deleted, another process held it and released (deleting the file).
// Check if that process already downloaded the browser.
if !lock.exists() && browser_binary_path.exists() {
// Another process may have downloaded the browser while this one waited for the lock
if browser_binary_path.exists() {
self.get_logger().debug(format!(
"{} {} now available at {}",
self.get_browser_name(),
Expand Down Expand Up @@ -1874,6 +1873,21 @@ mod tests {
assert_eq!(escaped, manager.canonicalize_path(folder));
}

#[test]
fn download_driver_returns_cached_jar_without_downloading() {
let tmp = tempfile::tempdir().unwrap();
let mut manager = crate::grid::GridManager::new("4.51.0".to_string()).unwrap();
manager.get_config_mut().cache_path = tmp.path().to_string_lossy().to_string();
let jar = manager.get_driver_path_in_cache().unwrap();
std::fs::create_dir_all(jar.parent().unwrap()).unwrap();
std::fs::write(&jar, b"cached").unwrap();

manager.download_driver().unwrap();

assert_eq!(std::fs::read(&jar).unwrap(), b"cached");
assert!(!jar.parent().unwrap().join("sm.lock").exists());
}

#[test]
fn prune_cache_entries_removes_old_driver_entries() {
let tmp = tempfile::tempdir().unwrap();
Expand Down
4 changes: 0 additions & 4 deletions rust/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ impl Lock {
}
set_lock_path(None);
}

pub fn exists(&mut self) -> bool {
self.path.exists()
}
Comment thread
bonigarcia marked this conversation as resolved.
Resolved
}

impl Drop for Lock {
Expand Down
Loading