Repository navigation
fix(test): stop two flaky tests from lying about the code - #845
Merged
Merged
Conversation
Three failures I met while working on the remote lane, all of them "the test
is wrong", none of them a product bug.
**The recommendation budget reset itself for the first eight hours of every
local day.** `today()` reads the local calendar day and says so in a comment
("`toISOString` is UTC, so it is not used here"), but the test seeded the
stored record with `new Date().toISOString().slice(0, 10)`. For a UTC+8 host
the two disagree between 00:00 and 08:00 local, `parseDay` saw a record from
"another day", discarded it, and the hook offered a skill it had already
shown — so the test failed only in that window, and only on hosts east of
UTC. The test now uses the production `today()`, which makes the two
calendars structurally impossible to drift apart.
A second test file pins the invariant itself, and does so at a fixed instant
with the local date parts forced to disagree with UTC: on a UTC host (what CI
runs) the two calendars otherwise always agree, so without forcing it the
assertion would be vacuous exactly where it needs to hold.
**The preview-cache sweep test raced a sibling over one process-wide
directory.** `preview_cache_dir()` is `$TMPDIR/futureos-attachments/mobile/
preview-cache` for the whole process, and `preview_cache_survives_transfer_
cleanup_and_invalidates_on_source_change` calls `clear_preview_cache()`,
which `remove_dir_all`s it — deleting the `fresh.jpg` the prune test was
about to assert on. It only failed under full-suite load, when the two
happen to interleave; in isolation it always passed.
Removing the shared state rather than serializing access to it: the sweep
now takes its directory as a parameter (the shape
`persist_image_preview_cache` already uses), the test passes its own, and
afterwards exactly one test touches the shared cache. Added a case for a
directory that does not exist, which is the state of every fresh install.
**Not fixed, and reported rather than papered over:**
`instance::tests::excludes_second_owner_and_releases_on_drop` failed once in
a full run and I could not reproduce it — 150 isolated runs, 320 concurrent
runs of the same binary, and 3 further full-suite runs all pass. No fix is
claimed here. One candidate worth a look if it recurs: `flock` is
interruptible, so an `EINTR` would take the "Could not lock…" arm of the
error message instead of "already running", which would fail this test's
assertions *and* show a confusing message to a user.
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.
Three failures met while working on the remote lane. All three are "the test is wrong" — none is a product bug — but two of them were hiding real behaviour behind a passing assertion, which is worse than a plain failure.
1. The recommendation budget reset itself for the first eight hours of every local day
today()reads the local calendar day and says so in a comment:/** Local calendar day. `toISOString` is UTC, so it is not used here. */The test then seeded the stored record with the UTC date:
On a UTC+8 host the two disagree between 00:00 and 08:00 local. In that window
parseDaysaw a record from "another day", discarded it, and the hook offered a skill it had already shown — so the test failed only at that hour, and only on hosts east of UTC. It looked like a passing suite every other time of day.The test now uses the production
today(), which makes the two calendars structurally impossible to drift apart.A second test pins the invariant, and does so at a fixed instant with the local date parts forced to disagree with UTC. This matters: CI runs on UTC, where the local and UTC calendars always agree, so the natural assertion would be vacuous exactly where it needs to hold. Forcing the disagreement with mocks keeps it meaningful on any host.
2. The preview-cache sweep raced a sibling over one process-wide directory
preview_cache_dir()is$TMPDIR/futureos-attachments/mobile/preview-cachefor the whole process, andpreview_cache_survives_transfer_cleanup_and_invalidates_on_source_changecallsclear_preview_cache(), whichremove_dir_alls it — deleting thefresh.jpgthe prune test was about to assert on. It failed only under full-suite load, when the two happen to interleave; in isolation it always passed.Fixed by removing the shared state rather than serializing access to it: the sweep now takes its directory as a parameter (the shape
persist_image_preview_cachealready uses), the test passes its own private one, and afterwards exactly one test touches the shared cache. A mutex would have worked too, but it would have left the hazard in place for the next test that forgets to take it.Added a case for a directory that does not exist — the state of every fresh install, and a path the sweep reaches on every transfer cycle.
3. Not fixed — reported instead
instance::tests::excludes_second_owner_and_releases_on_dropfailed once in a full run and I could not reproduce it: 150 isolated runs, 320 concurrent runs of the same test binary, and 3 further full-suite runs all pass. I am not claiming a fix for it.One candidate if it recurs:
flockis interruptible, so anEINTRwould land in the"Could not lock Desktop data directory…: {e}"arm instead of the contended"Desktop is already running"arm — failing this test's assertions and showing a confusing message to a real user. That is a hypothesis, not a diagnosis, and it is not changed here.Verification
cargo fmt --check+cargo clippy --all-targets -D warningsclean on pinned 1.97.today()totoISOStringfails both new assertions.