k8s_test_framework/lock.rs
1use std::sync::{Mutex, MutexGuard};
2
3/// A shared lock to use commonly among the tests.
4/// The goal is to guarantee that only one test is executing concurrently, since
5/// tests use a shared resource - a k8s cluster - and will conflict with each
6/// other unless they're executing sequentially.
7pub fn lock() -> MutexGuard<'static, ()> {
8 static INSTANCE: Mutex<()> = Mutex::new(());
9 match INSTANCE.lock() {
10 Ok(guard) => guard,
11 // Ignore poison error.
12 Err(err) => err.into_inner(),
13 }
14}