Skip to content

test: wait for the page's own looks and clock before the freshness tests' absence checks - #5603

Merged
leaf-agent merged 1 commit into
mainfrom
nightly/freshness-absence-waits
Nov 6, 2026
Merged

leaf-agent merged 1 commit into
mainfrom
nightly/freshness-absence-waits

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

Four tests in tests/browser/startup/test_freshness.py slept for a fixed time and then checked that something had not happened: the page asking for state, reloading, or looking for news while hidden. On a slow machine the unwanted request or reload can arrive after the sleep, so the test passes with the bug present. That breaks the rule in tests/AGENTS.md, "Absences", and #5541's sweep missed this file. Each check now waits for something the page itself does after the moment it would have misbehaved. The page counts its own requests (COUNT_ASKS, moved to the top of the file). Each rewritten check failed with the bug it guards against planted in browser/runtime/state-feed.js, and all twelve tests in the file pass without it.

Test Slept Now waits for Planted fault it caught
test_a_quiet_page_reads_only_freshness_and_hears_changes 3 s a round of the shared clock, then a freshness check the page finished the clock asking for state every round (asks = true || …)
test_a_durable_server_restart_keeps_the_current_editor 500 ms the page's next freshness check after the one that saw the new server, or a reloaded document, whichever comes first a reload 100 ms after seeing the new server
test_a_hidden_page_stops_its_freshness_reads_until_it_is_visible 500 ms a round of the shared clock; it now also checks that no freshness request was sent after the page hid a hidden page that keeps checking (stopListening not called)
test_a_page_whose_read_failed_asks_again_on_its_own 1 s eight freshness checks; it then allows one state read per round of the clock, timed by the page's own clock, plus one every check asking for state (if (true) item(observed)), which made 9 reads in about 2 s

ran_its_clock has the page set a timer one interval of the shared clock long (TICK_MS, plus 500 ms). The browser fires timers in deadline order, so the clock's next round and any freshness check still scheduled run before it, however slowly the machine runs them. A fixed sleep, by contrast, runs on the test's clock, which knows nothing about the page's timers. TICK_MS is copied from state-feed.js, and a comment says so.

The 100 ms sleep before the hidden-page test writes its news is left in place: it is setup, not a check that something stayed absent.

…sts' absence checks

Four tests in tests/browser/startup/test_freshness.py slept a fixed time (3 s,
500 ms, 500 ms, 1 s) and then asserted that the page had not asked for state, not
reloaded, or not looked while hidden. On a slower machine the unwanted ask lands
after the sleep and the test passes with the bug present, against
tests/AGENTS.md's "Absences"; #5541's sweep missed this file.

Each now waits for an event the page orders after the moment it would have
misbehaved, counting asks in the page (COUNT_ASKS, moved to the top):

- A quiet page: a round of the shared clock (`ran_its_clock`, a page timer longer
  than TICK_MS, which the page fires after every timer due before it), then a
  handled look (`looked_since`).
- A durable restart: the look after the one that heard the new server, or a
  reloaded document, whichever comes first.
- A hidden page: a round of the clock, with the looks it asked counted from the
  moment it hid, so a look it failed to cancel shows as well as a state read.
- A page whose read failed: eight looks, allowing one ask per round of the clock
  by the page's own time, plus one.

Each failed with the behavior it guards planted in state-feed.js: every look
asking for state, the clock asking every round, a hidden page left listening, and
a reload on the new server.
@leaf-agent
leaf-agent merged commit 78445a3 into main Nov 6, 2026
6 checks passed
@leaf-agent
leaf-agent deleted the nightly/freshness-absence-waits branch November 6, 2026 07:14
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