Skip to content

Commit

Permalink
test: add serial lock for lockfile tests (#9403)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jul 9, 2024
1 parent 0a27779 commit 7dab636
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/storage/db/src/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,19 @@ impl ProcessUID {
#[cfg(test)]
mod tests {
use super::*;
use std::sync::{Mutex, MutexGuard, OnceLock};

// helper to ensure some tests are run serially
static SERIAL: OnceLock<Mutex<()>> = OnceLock::new();

fn serial_lock() -> MutexGuard<'static, ()> {
SERIAL.get_or_init(|| Mutex::new(())).lock().unwrap()
}

#[test]
fn test_lock() {
let _guard = serial_lock();

let temp_dir = tempfile::tempdir().unwrap();

let lock = StorageLock::try_acquire(temp_dir.path()).unwrap();
Expand Down Expand Up @@ -178,6 +188,8 @@ mod tests {

#[test]
fn test_drop_lock() {
let _guard = serial_lock();

let temp_dir = tempfile::tempdir().unwrap();
let lock_file = temp_dir.path().join(LOCKFILE_NAME);

Expand Down

0 comments on commit 7dab636

Please sign in to comment.