test: add serial lock for lockfile tests (#9403)

This commit is contained in:
Matthias Seitz
2024-07-09 19:24:26 +02:00
committed by GitHub
parent 0a27779375
commit 7dab636b04

View File

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