Repository navigation
test: keep import creation-dates in step with the pinned clock - #437
Merged
Merged
Conversation
The cmd/things tests pin the clock to testNow when the process starts, but several import tests built a creation-date from time.Now. The future-date refusal reads the pinned clock with a minute's slack, so once the package had run for over a minute (slow -race CI) the date counted as future and the import was refused. Those tests now pin the clock to the wall time for their own run, since their date must also fall inside the read-back window, which reads the wall clock. TestImportChecksWhen built today's startDate from the wall clock too, which disagreed with the pinned day on a run crossing midnight; it now uses testNow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The cmd/things tests pin the clock to
testNowwhen the package starts, but several import tests built acreation-datefromtime.Now(). The import refuses a date in the future using the pinned clock, with a minute's slack. So once the package had run for more than a minute, which happens on a slow-racerun in CI, those dates counted as future and the import was refused. This is why 7 import tests failed on #432 although that change does not touch them.Those tests can't just switch to
testNow, because their date also has to fall inside the read-back window, and that window reads the wall clock. Instead a newpinWallClock(t)helper pins the clock to the wall time for the length of the test.recentCreationDatenow takestand calls it itself, so a test that uses it can't forget the pin. The three tests that build the date in other ways call it directly.TestImportChecksWhenbuilt today'sstartDatefrom the wall clock while the--whencheck reads the pinned day, so itstodayLandedcase failed on a run that crossed midnight. It now usestestNow.How I checked: with
testNowset 2 minutes behind the wall clock, 6 tests failed on main and all pass on this branch. WithtestNowset a day behind,TestImportChecksWhen/todayLandedfails without the change and passes with it. Both hacks were reverted, andmake testandmake lintpass.Uses of
time.Now()left alone, because they are compared against the wall clock or the margin is too wide for drift to matter: thecreationDateseeds instubExecAddingand the "created before" tests (read-back snapshot window), thereadBackCreatesunit tests, the stale-cache tests (time.Since),TestClosedTitleRecency, the verify timeout test, the deadline 4 days in the past inTestImportChecksWhen, and the start date 3 days ahead inTestAddWhenPhraseIgnored, which passed with the day shift.