Skip to content

test: keep import creation-dates in step with the pinned clock - #437

Merged
ryanlewis merged 2 commits into
mainfrom
fix/test-wall-clock
Oct 9, 2026
Merged

ryanlewis merged 2 commits into
mainfrom
fix/test-wall-clock

Conversation

@ryanlewis

Copy link
Copy Markdown
Owner

The cmd/things tests pin the clock to testNow when the package starts, but several import tests built a creation-date from time.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 -race run 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 new pinWallClock(t) helper pins the clock to the wall time for the length of the test. recentCreationDate now takes t and 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.

TestImportChecksWhen built today's startDate from the wall clock while the --when check reads the pinned day, so its todayLanded case failed on a run that crossed midnight. It now uses testNow.

How I checked: with testNow set 2 minutes behind the wall clock, 6 tests failed on main and all pass on this branch. With testNow set a day behind, TestImportChecksWhen/todayLanded fails without the change and passes with it. Both hacks were reverted, and make test and make lint pass.

Uses of time.Now() left alone, because they are compared against the wall clock or the margin is too wide for drift to matter: the creationDate seeds in stubExecAdding and the "created before" tests (read-back snapshot window), the readBackCreates unit tests, the stale-cache tests (time.Since), TestClosedTitleRecency, the verify timeout test, the deadline 4 days in the past in TestImportChecksWhen, and the start date 3 days ahead in TestAddWhenPhraseIgnored, which passed with the day shift.

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.
@ryanlewis
ryanlewis merged commit 4ef130d into main Oct 9, 2026
8 checks passed
@ryanlewis
ryanlewis deleted the fix/test-wall-clock branch October 9, 2026 23:33
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.

1 participant