Skip to content

Commit c8a1319

Browse files
committed
avoid racyness in worktree tests (#301)
1 parent 21d6f88 commit c8a1319

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

git-worktree/tests/worktree/index/checkout.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -287,21 +287,27 @@ fn keep_going_collects_results() {
287287
)
288288
.unwrap();
289289

290-
assert_eq!(
291-
sort_when_threaded(
290+
if multi_threaded() {
291+
assert_eq!(
292+
outcome.errors.len(),
293+
2,
294+
"content changes due to non-deterministic nature of racy threads"
295+
)
296+
} else {
297+
assert_eq!(
292298
outcome
293299
.errors
294300
.iter()
295301
.map(|r| r.path.to_path_lossy().into_owned())
296-
.collect()
297-
),
298-
sort_when_threaded(paths(if cfg!(unix) {
299-
["dir/content", "empty"]
300-
} else {
301-
// not actually a symlink anymore, even though symlinks are supported but git think differently.
302-
["dir/content", "dir/sub-dir/symlink"]
303-
}))
304-
);
302+
.collect::<Vec<_>>(),
303+
paths(if cfg!(unix) {
304+
["dir/content", "empty"]
305+
} else {
306+
// not actually a symlink anymore, even though symlinks are supported but git think differently.
307+
["dir/content", "dir/sub-dir/symlink"]
308+
})
309+
);
310+
}
305311

306312
assert_eq!(
307313
stripped_prefix(&destination, &dir_structure(&destination)),
@@ -349,8 +355,7 @@ fn collisions_are_detected_on_a_case_insensitive_filesystem() {
349355
);
350356

351357
let dest_files = dir_structure(&destination);
352-
let multi_threaded = git_features::parallel::num_threads(None) > 1;
353-
if multi_threaded {
358+
if multi_threaded() {
354359
assert_eq!(
355360
dest_files.len(),
356361
5,
@@ -370,7 +375,7 @@ fn collisions_are_detected_on_a_case_insensitive_filesystem() {
370375
#[cfg(not(windows))]
371376
let error_kind_dir = error_kind;
372377

373-
if multi_threaded {
378+
if multi_threaded() {
374379
assert_eq!(
375380
outcome.collisions.len(),
376381
5,
@@ -406,6 +411,10 @@ fn collisions_are_detected_on_a_case_insensitive_filesystem() {
406411
}
407412
}
408413

414+
fn multi_threaded() -> bool {
415+
git_features::parallel::num_threads(None) > 1
416+
}
417+
409418
fn assert_equality(source_tree: &Path, destination: &TempDir, allow_symlinks: bool) -> crate::Result<usize> {
410419
let source_files = dir_structure(source_tree);
411420
let worktree_files = dir_structure(&destination);
@@ -517,13 +526,3 @@ fn opts_from_probe() -> index::checkout::Options {
517526
fn paths<'a>(p: impl IntoIterator<Item = &'a str>) -> Vec<PathBuf> {
518527
p.into_iter().map(PathBuf::from).collect()
519528
}
520-
521-
fn sort_when_threaded<T>(mut p: Vec<T>) -> Vec<T>
522-
where
523-
T: Ord,
524-
{
525-
if git_features::parallel::num_threads(None) > 1 {
526-
p.sort()
527-
}
528-
p
529-
}

0 commit comments

Comments
 (0)