test cleanup

This commit is contained in:
Cyryl Płotnicki 2021-01-09 14:57:04 +00:00
parent 6567d38e23
commit 175e5e327f
2 changed files with 8 additions and 17 deletions

View file

@ -13,6 +13,7 @@ pub struct Lock {
} }
const MAX_TIMEOUT_MILLIS: u16 = 8192; const MAX_TIMEOUT_MILLIS: u16 = 8192;
const FILE_EXTENSION: &str = ".lock";
impl Lock { impl Lock {
pub fn lock(index_directory: &VfsPath) -> Result<Self> { pub fn lock(index_directory: &VfsPath) -> Result<Self> {
@ -78,7 +79,7 @@ impl Lock {
Ok(index_directory Ok(index_directory
.read_dir()? .read_dir()?
.into_iter() .into_iter()
.filter(|f| f.filename().ends_with(".lock")) .filter(|f| f.filename().ends_with(FILE_EXTENSION))
.collect()) .collect())
} }
@ -92,7 +93,7 @@ impl Lock {
} }
fn lock_file_path(path: &VfsPath, lock_id: Uuid) -> Result<VfsPath> { fn lock_file_path(path: &VfsPath, lock_id: Uuid) -> Result<VfsPath> {
let file_name = format!("{}.lock", lock_id); let file_name = format!("{}.{}", lock_id, FILE_EXTENSION);
Ok(path.join(&file_name)?) Ok(path.join(&file_name)?)
} }
} }
@ -108,8 +109,6 @@ mod must {
use super::Lock; use super::Lock;
use anyhow::Result; use anyhow::Result;
#[cfg(feature = "failpoints")]
use fail::FailScenario;
#[cfg(feature = "failpoints")] #[cfg(feature = "failpoints")]
use two_rusty_forks::rusty_fork_test; use two_rusty_forks::rusty_fork_test;
use vfs::{MemoryFS, VfsPath}; use vfs::{MemoryFS, VfsPath};
@ -130,16 +129,11 @@ mod must {
rusty_fork_test! { rusty_fork_test! {
#[test] #[test]
fn be_able_to_lock_when_creating_lock_file_fails_sometimes() { fn be_able_to_lock_when_creating_lock_file_fails_sometimes() {
let scenario = FailScenario::setup();
fail::cfg("create-lock-file", "90%10*return(some lock file creation error)->off").unwrap(); fail::cfg("create-lock-file", "90%10*return(some lock file creation error)->off").unwrap();
let path = MemoryFS::new().into();
{ let lock = Lock::lock(&path).unwrap();
let path = MemoryFS::new().into(); lock.release().unwrap();
let lock = Lock::lock(&path).unwrap();
lock.release().unwrap();
}
scenario.teardown();
} }
} }
@ -147,13 +141,10 @@ mod must {
rusty_fork_test! { rusty_fork_test! {
#[test] #[test]
fn know_to_give_up_when_creating_lock_file_always_fails() { fn know_to_give_up_when_creating_lock_file_always_fails() {
let scenario = FailScenario::setup();
fail::cfg("create-lock-file", "return(persistent lock file creation error)").unwrap(); fail::cfg("create-lock-file", "return(persistent lock file creation error)").unwrap();
let path = MemoryFS::new().into(); let path = MemoryFS::new().into();
assert!(Lock::lock_with_timeout(&path, 1).is_err());
scenario.teardown(); assert!(Lock::lock_with_timeout(&path, 1).is_err());
} }
} }
} }

View file

@ -165,7 +165,7 @@ pub mod in_memory {
} }
} }
result.sort_by(|a, b| a.filename().cmp(&b.filename())); result.sort_by_key(|a| a.filename());
Ok(result) Ok(result)
} }