From 7dab636b0488b916d602f890537252a6771d107d Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 9 Jul 2024 19:24:26 +0200 Subject: [PATCH] test: add serial lock for lockfile tests (#9403) --- crates/storage/db/src/lockfile.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/storage/db/src/lockfile.rs b/crates/storage/db/src/lockfile.rs index e0da20348..828cec6e7 100644 --- a/crates/storage/db/src/lockfile.rs +++ b/crates/storage/db/src/lockfile.rs @@ -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> = 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(); @@ -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);