Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: fix mtime flakiness in git gc tests #3539

Merged
merged 2 commits into from
Apr 22, 2024

Conversation

yuja
Copy link
Collaborator

@yuja yuja commented Apr 19, 2024

#3537

@thoughtpolice can you try this patch? I cannot reproduce the problem reliably at my end.

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

@thoughtpolice
Copy link
Collaborator

I just blindly ran for x in $(seq 1 20); do cargo nextest run --workspace; done since in my experience the failure rate is higher than ~5%, and unfortunately after 10-15 runs it failed again, with a slightly different LHS/RHS:

--- STDOUT:              jj-lib::runner test_git_backend::test_gc ---

running 1 test
git version 2.44.0
test test_git_backend::test_gc ... FAILED

failures:

failures:
    test_git_backend::test_gc

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 315 filtered out; finished in 0.32s


--- STDERR:              jj-lib::runner test_git_backend::test_gc ---
thread 'test_git_backend::test_gc' panicked at lib/tests/test_git_backend.rs:154:5:
assertion `left == right` failed
  left: {CommitId("395234a1c7b881d22499564b5d2196203ac6d782"), CommitId("ae36ec61acbca7209121052dda43f9ca9db90817")}
 right: {CommitId("ae36ec61acbca7209121052dda43f9ca9db90817"), CommitId("7231fd316deb9d5c8f479e625dba6a9004dddc30"), CommitId("395234a1c7b881d22499564b5d2196203ac6d782")}

Maybe 1 second isn't enough? I haven't spent time looking at the test since I figured you'd have a better idea anyway :)

@yuja
Copy link
Collaborator Author

yuja commented Apr 20, 2024

left: {CommitId("395234a1c7b881d22499564b5d2196203ac6d782"), CommitId("ae36ec61acbca7209121052dda43f9ca9db90817")}
right: {CommitId("ae36ec61acbca7209121052dda43f9ca9db90817"), CommitId("7231fd316deb9d5c8f479e625dba6a9004dddc30"), CommitId("395234a1c7b881d22499564b5d2196203ac6d782")}

Ok, this appears to be an mtime problem in gix. GitBackend::gc() first updates refs internally by using gix API, then spawns git gc process. If git gc quickly rewrites the packed refs, gix can't detect the change because mtime is the same. Perhaps, we can get around the problem by reloading the refs store or gix repo.

@yuja
Copy link
Collaborator Author

yuja commented Apr 21, 2024

Updated tests to not rely on in-memory cache. I've tested the change on old ext3 image (of 1sec timestamp accuracy) where the problem can be ~100% reproduced.

Copy link
Owner

@martinvonz martinvonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing.

Copy link
Collaborator

@thoughtpolice thoughtpolice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My test of 20 runs went through fine, thanks a lot!

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 addresses the test instability. The underlying problem still exists, but
it's unlikely to trigger user-facing issues because of that. A repo instance
won't be reused after gc() call.

Fixes martinvonz#3537
@yuja yuja enabled auto-merge (rebase) April 22, 2024 09:39
@yuja yuja merged commit 9f4a731 into martinvonz:main Apr 22, 2024
16 checks passed
@yuja yuja deleted the push-rxsvzzsxtlyk branch April 22, 2024 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants