Skip to content

Commit

Permalink
tests: fix flakiness in shallow Git repo test
Browse files Browse the repository at this point in the history
This test reliably failed if I dropped tv_nsec part from statx().

Since we reload the repo now, several assertions get "fixed". I've added
index().has_id() test to clarify that it's still broken.
  • Loading branch information
yuja committed Nov 12, 2024
1 parent 9ea91dc commit 7be4904
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/tests/test_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3485,6 +3485,7 @@ ignoreThisSection = foo
fn test_shallow_commits_lack_parents() {
let settings = testutils::user_settings();
let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git);
let test_env = &test_repo.env;
let repo = &test_repo.repo;
let git_repo = get_git_repo(repo);

Expand Down Expand Up @@ -3515,8 +3516,10 @@ fn test_shallow_commits_lack_parents() {
writeln!(buf, "{commit}").unwrap();
}
fs::write(shallow_file, buf).unwrap();
// Reload the repo to invalidate mtime-based in-memory cache
test_env.load_repo_at_head(&settings, test_repo.repo_path())
};
make_shallow(repo, vec![b.id(), c.id()]);
let repo = make_shallow(repo, vec![b.id(), c.id()]);

let mut tx = repo.start_transaction(&settings);
git::import_refs(tx.repo_mut(), &GitSettings::default()).unwrap();
Expand Down Expand Up @@ -3547,7 +3550,7 @@ fn test_shallow_commits_lack_parents() {
);

// deepen the shallow clone
make_shallow(&repo, vec![a.id()]);
let repo = make_shallow(&repo, vec![a.id()]);

let mut tx = repo.start_transaction(&settings);
git::import_refs(tx.repo_mut(), &GitSettings::default()).unwrap();
Expand All @@ -3560,15 +3563,16 @@ fn test_shallow_commits_lack_parents() {
vec![root.clone()],
"shallow commits have the root commit as a parent"
);
// TODO: These should be assert_eq!
assert_ne!(
assert_eq!(
parents(store, &b),
vec![jj_id(&a)],
"unshallowed commits have parents"
);
assert_ne!(
assert_eq!(
parents(store, &c),
vec![jj_id(&a)],
"unshallowed commits have correct parents"
);
// FIXME: new ancestors should be indexed
assert!(!repo.index().has_id(&jj_id(&a)));
}

0 comments on commit 7be4904

Please sign in to comment.