From 8fceafc3e1f2d84299e4f2102881ec15c9688395 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 30 Jun 2024 13:17:33 +0100 Subject: [PATCH] refactor: repo-actor: replace Mutex with RwLock --- crates/repo-actor/src/tests/handlers/clone_repo.rs | 12 ++++++------ crates/repo-actor/src/tests/mod.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/repo-actor/src/tests/handlers/clone_repo.rs b/crates/repo-actor/src/tests/handlers/clone_repo.rs index 3e1492ed..8b8c1ce8 100644 --- a/crates/repo-actor/src/tests/handlers/clone_repo.rs +++ b/crates/repo-actor/src/tests/handlers/clone_repo.rs @@ -15,13 +15,13 @@ async fn should_clone() -> TestResult { // factory clones an open repository let mut repository_factory = MockRepositoryFactory::new(); - let cloned = Arc::new(Mutex::new(vec![])); + let cloned = Arc::new(RwLock::new(vec![])); let cloned_ref = cloned.clone(); repository_factory .expect_git_clone() .times(2) .return_once(move |_| { - let _ = cloned_ref.lock().map(|mut l| l.push(())); + let _ = cloned_ref.write().map(|mut l| l.push(())); Ok(Box::new(open_repository)) }); @@ -32,7 +32,7 @@ async fn should_clone() -> TestResult { //then cloned - .lock() + .read() .map_err(|e| e.to_string()) .map(|o| assert_eq!(o.len(), 1))?; @@ -52,13 +52,13 @@ async fn should_open() -> TestResult { // factory opens a repository let mut repository_factory = MockRepositoryFactory::new(); - let opened = Arc::new(Mutex::new(vec![])); + let opened = Arc::new(RwLock::new(vec![])); let opened_ref = opened.clone(); repository_factory .expect_open() .times(1) .return_once(move |_| { - let _ = opened_ref.lock().map(|mut l| l.push(())); + let _ = opened_ref.write().map(|mut l| l.push(())); Ok(Box::new(open_repository)) }); fs.dir_create(&repo_details.gitdir)?; @@ -70,7 +70,7 @@ async fn should_open() -> TestResult { //then opened - .lock() + .read() .map_err(|e| e.to_string()) .map(|o| assert_eq!(o.len(), 1))?; diff --git a/crates/repo-actor/src/tests/mod.rs b/crates/repo-actor/src/tests/mod.rs index 4ca85b0d..4dec73fc 100644 --- a/crates/repo-actor/src/tests/mod.rs +++ b/crates/repo-actor/src/tests/mod.rs @@ -22,7 +22,7 @@ use git_next_git as git; use mockall::predicate::eq; use std::{ collections::{BTreeMap, HashMap}, - sync::{Arc, Mutex}, + sync::{Arc, RwLock}, }; type TestResult = Result<(), Box>;