test: stop AccountTest failing when the second ticks mid-test - #896
Merged
blaipr merged 1 commit intoAug 30, 2026
Merged
Conversation
`AccountUseCases::create()` and `::updatePassword()` stamp `passDate` with `time()`, and five expectations in AccountTest built theirs by calling the same factory — so the test called time() a moment before the production code did. Whenever the second ticked between the two, the models differed by one and the test failed: a real CI failure, in whichever pull request happened to be open, that could not be reproduced on demand. `anAccountStampedNow()` compares everything else exactly and takes only `passDate` from the actual model, after checking it is a timestamp from the last few seconds — so a factory that stopped stamping it, or stamped something else, still fails. Shown both ways with a `sleep(1)` injected before the write: the old expectations fail all five, the new ones pass all five, and a service mutated to pass a different DTO still fails them.
blaipr
deleted the
test/a-stamped-timestamp-does-not-fail-when-the-second-ticks
branch
August 30, 2026 14:22
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.
AccountUseCases::create()and::updatePassword()stamppassDatewithtime(). Fiveexpectations in
AccountTestbuilt theirs by calling the same factory, a moment before theproduction code called it — so whenever the second ticked between the two, the two models differed
by exactly one and the test failed:
It is a real failure with nothing wrong in the code, it lands in whichever pull request happens to
be open, and it cannot be reproduced on demand — which is what made it read as a mystery rather
than a bug. It failed the 8.5 unit job on #895 while 8.4 passed on the same commit.
The change
anAccountStampedNow()compares everything else exactly and takes onlypassDatefrom the actualmodel, after checking it is a timestamp from the last few seconds. A factory that stopped stamping
it, or stamped something else, still fails.
Shown both ways
With
sleep(1)injected before the repository write, to make the race happen every time:sleep(1)before the writeThe second row is what keeps the matcher honest: it is tolerant of the timestamp and of nothing
else. Mutating the factory itself proves nothing here and was discarded — the test builds its
expectation with that factory, so a change to it moves both sides equally.