Skip to content

Commit

Permalink
tests: fix potential mtime flakiness in git gc tests
Browse files Browse the repository at this point in the history
Apparently, these gc() invocations rely on that the previous "git gc" packed
all refs so there are no loose refs to compare mtimes. If there were new (or
remaining) loose refs, mtime comparison could fail. I also added +1sec to
effectively turn off the keep_newer option, which isn't important in these
tests.
  • Loading branch information
yuja committed Apr 22, 2024
1 parent f9a3021 commit 3b8fbcc
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/tests/test_git_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use std::collections::HashSet;
use std::process::Command;
use std::sync::Arc;
use std::time::SystemTime;
use std::time::{Duration, SystemTime};

use jj_lib::backend::CommitId;
use jj_lib::git_backend::GitBackend;
Expand Down Expand Up @@ -126,9 +126,12 @@ fn test_gc() {
},
);

// Don't rely on the exact system time because file modification time might
// have lower precision for example.
let now = || SystemTime::now() + Duration::from_secs(1);

// All reachable: redundant no-gc refs will be removed
let now = SystemTime::now();
repo.store().gc(repo.index(), now).unwrap();
repo.store().gc(repo.index(), now()).unwrap();
assert_eq!(
collect_no_gc_refs(&git_repo),
hashset! {
Expand All @@ -147,7 +150,7 @@ fn test_gc() {
mut_index.add_commit(&commit_e);
mut_index.add_commit(&commit_f);
mut_index.add_commit(&commit_h);
repo.store().gc(mut_index.as_index(), now).unwrap();
repo.store().gc(mut_index.as_index(), now()).unwrap();
assert_eq!(
collect_no_gc_refs(&git_repo),
hashset! {
Expand All @@ -163,7 +166,7 @@ fn test_gc() {
mut_index.add_commit(&commit_b);
mut_index.add_commit(&commit_c);
mut_index.add_commit(&commit_f);
repo.store().gc(mut_index.as_index(), now).unwrap();
repo.store().gc(mut_index.as_index(), now()).unwrap();
assert_eq!(
collect_no_gc_refs(&git_repo),
hashset! {
Expand All @@ -175,7 +178,7 @@ fn test_gc() {
// B|C|F are no longer reachable
let mut mut_index = base_index.start_modification();
mut_index.add_commit(&commit_a);
repo.store().gc(mut_index.as_index(), now).unwrap();
repo.store().gc(mut_index.as_index(), now()).unwrap();
assert_eq!(
collect_no_gc_refs(&git_repo),
hashset! {
Expand All @@ -184,6 +187,6 @@ fn test_gc() {
);

// All unreachable
repo.store().gc(base_index.as_index(), now).unwrap();
repo.store().gc(base_index.as_index(), now()).unwrap();
assert_eq!(collect_no_gc_refs(&git_repo), hashset! {});
}

0 comments on commit 3b8fbcc

Please sign in to comment.