-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: MOZGIII <[email protected]>
- Loading branch information
Showing
4 changed files
with
19 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use once_cell::sync::OnceCell; | ||
use std::sync::{Mutex, MutexGuard}; | ||
|
||
/// A shared lock to use commonly among the tests. | ||
/// The goal is to guranatee that only one test is executing concurrently, since | ||
/// tests use a shared resource - a k8s cluster - and will conflict with each | ||
/// other unless they're executing sequentially. | ||
pub fn lock() -> MutexGuard<'static, ()> { | ||
static INSTANCE: OnceCell<Mutex<()>> = OnceCell::new(); | ||
match INSTANCE.get_or_init(|| Mutex::new(())).lock() { | ||
Ok(guard) => guard, | ||
// Ignore poison error. | ||
Err(err) => err.into_inner(), | ||
} | ||
} |