Skip to content

Commit a9feaea

Browse files
committed
test: guard sl tests with mutex
sapling seems to be quite flaky when invoked in parallel from different processes. Introduce a mutex to guard invocations in the sl binary.
1 parent 79f46b0 commit a9feaea

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ figment = { version = "0.10", features = ["toml", "env"] }
3232
[dev-dependencies]
3333
assert_cmd = "2.0.4"
3434
insta = { version = "1.20.0", features = ["redactions", "yaml"] }
35+
once_cell = "1.19.0"

src/sapling.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ impl version_control::System for Repo {
8888

8989
#[cfg(test)]
9090
mod tests {
91-
use std::{fs::OpenOptions, io::Write};
91+
use once_cell::sync::Lazy;
92+
use std::{fs::OpenOptions, io::Write, sync::Mutex}; // 1.4.0
9293

94+
static SL_GLOBAL_MUTEX: Lazy<Mutex<()>> = Lazy::new(Mutex::default);
9395
use crate::testing;
9496

9597
use super::*;
@@ -103,6 +105,7 @@ mod tests {
103105

104106
impl SaplingClone {
105107
fn new(git_repo: &testing::GitCheckout) -> Result<SaplingClone> {
108+
let _shared = SL_GLOBAL_MUTEX.lock().unwrap();
106109
let temp_dir = TempDir::new()?;
107110
assert_eq!(
108111
std::process::Command::new("sl")
@@ -123,6 +126,7 @@ mod tests {
123126
}
124127

125128
fn run(&self, subcommand: &str) -> std::process::Command {
129+
let _shared = SL_GLOBAL_MUTEX.lock().unwrap();
126130
let mut cmd = std::process::Command::new("sl");
127131
cmd.current_dir(&self.root);
128132
cmd.arg(subcommand);
@@ -169,6 +173,7 @@ mod tests {
169173
}
170174

171175
fn changed_files(&self, relative_to: Option<&str>) -> Result<Vec<String>> {
176+
let _shared = SL_GLOBAL_MUTEX.lock().unwrap();
172177
std::env::set_current_dir(&self.root)?;
173178
use version_control::System;
174179
let repo = Repo::new()?;
@@ -181,6 +186,7 @@ mod tests {
181186
}
182187

183188
fn merge_base_with(&self, merge_base_with: &str) -> Result<String> {
189+
let _shared = SL_GLOBAL_MUTEX.lock().unwrap();
184190
std::env::set_current_dir(&self.root)?;
185191
use version_control::System;
186192
let repo = Repo::new()?;

0 commit comments

Comments
 (0)