refactor: repo-actor: replace Mutex with RwLock
All checks were successful
Rust / build (push) Successful in 1m17s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful

This commit is contained in:
Paul Campbell 2024-06-30 13:17:33 +01:00
parent 73b416e3a0
commit 8fceafc3e1
2 changed files with 7 additions and 7 deletions

View file

@ -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))?;

View file

@ -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<dyn std::error::Error>>;