tests: fix potential mtime flakiness in git gc tests

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.
This commit is contained in:
Yuya Nishihara 2024-04-19 12:51:06 +09:00
parent f9a3021a7a
commit 527713a851

View file

@ -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;
@ -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! {
@ -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! {
@ -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! {
@ -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! {
@ -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! {});
}