refactor: repo-actor: replace Mutex with RwLock
This commit is contained in:
parent
73b416e3a0
commit
8fceafc3e1
2 changed files with 7 additions and 7 deletions
|
@ -15,13 +15,13 @@ async fn should_clone() -> TestResult {
|
||||||
|
|
||||||
// factory clones an open repository
|
// factory clones an open repository
|
||||||
let mut repository_factory = MockRepositoryFactory::new();
|
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();
|
let cloned_ref = cloned.clone();
|
||||||
repository_factory
|
repository_factory
|
||||||
.expect_git_clone()
|
.expect_git_clone()
|
||||||
.times(2)
|
.times(2)
|
||||||
.return_once(move |_| {
|
.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))
|
Ok(Box::new(open_repository))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ async fn should_clone() -> TestResult {
|
||||||
|
|
||||||
//then
|
//then
|
||||||
cloned
|
cloned
|
||||||
.lock()
|
.read()
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
.map(|o| assert_eq!(o.len(), 1))?;
|
.map(|o| assert_eq!(o.len(), 1))?;
|
||||||
|
|
||||||
|
@ -52,13 +52,13 @@ async fn should_open() -> TestResult {
|
||||||
|
|
||||||
// factory opens a repository
|
// factory opens a repository
|
||||||
let mut repository_factory = MockRepositoryFactory::new();
|
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();
|
let opened_ref = opened.clone();
|
||||||
repository_factory
|
repository_factory
|
||||||
.expect_open()
|
.expect_open()
|
||||||
.times(1)
|
.times(1)
|
||||||
.return_once(move |_| {
|
.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))
|
Ok(Box::new(open_repository))
|
||||||
});
|
});
|
||||||
fs.dir_create(&repo_details.gitdir)?;
|
fs.dir_create(&repo_details.gitdir)?;
|
||||||
|
@ -70,7 +70,7 @@ async fn should_open() -> TestResult {
|
||||||
|
|
||||||
//then
|
//then
|
||||||
opened
|
opened
|
||||||
.lock()
|
.read()
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
.map(|o| assert_eq!(o.len(), 1))?;
|
.map(|o| assert_eq!(o.len(), 1))?;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ use git_next_git as git;
|
||||||
use mockall::predicate::eq;
|
use mockall::predicate::eq;
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, HashMap},
|
collections::{BTreeMap, HashMap},
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, RwLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
type TestResult = Result<(), Box<dyn std::error::Error>>;
|
type TestResult = Result<(), Box<dyn std::error::Error>>;
|
||||||
|
|
Loading…
Reference in a new issue