Skip to content

test(explorer): wait for every API answer before ending the image-flood step - #246

Merged
tunjayoff merged 1 commit into
mainfrom
test/explorer-flood-flake
Nov 21, 2026
Merged

tunjayoff merged 1 commit into
mainfrom
test/explorer-flood-flake

Conversation

@tunjayoff

Copy link
Copy Markdown
Owner

Fixes the flake in tests/test_research_explorer.py::test_explorer_records_every_request_under_an_image_flood (browser bridge (offline) job). It failed once on the v3.2.0 release run (assert '0' == '12' at the title check); the same commit passed on the PR's CI.

Cause

Explorer.goto waits through _settle(settle, dwell): it sleeps settle s, then keeps waiting only while the last API activity (last_api, set when a slot is granted and when a response arrives) is less than settle s old. That is a quiet window, not "all of the page's requests answered". In this test settle is 2 s. Under the 12,000-image flood every paused image goes through the same asyncio loop and CDP pipe as the API requests. Each API request also needs two Fetch.getResponseBody liveness round trips and a thread hop for the rate slot. So the interceptor can stay quiet for 2 s (title 0 means no answer at all had reached the page), and goto returns early. The test then set ex.active = False straight away and read the title.

Change (test only)

  • Keep res["error"] is None. Then wait for what the test means, page.wait_for_function("document.title === '12'"), with a timeout of (N_API * gap + 60) s = 64.8 s.
  • Wait before ex.active = False. An inactive step drops requests that are still queued, so waiting after it would let the title reach 12 through dropped (failed) fetches and the run would then fail on api_hits.
  • Every other assertion is unchanged: API hit count, slot gap ≥ 0.95·gap, spread, flood count ≥ FLOOD, idle drop, rows, elapsed < 80.

No product change and no CHANGELOG entry (tests only).

Runs (local, offline)

  • Unmodified test, idle machine: 3 passes (≈12 s each). Instrumented runs showed goto ≈10 s for 12 slots, with slot gaps up to ~0.7 s under the flood.
  • Unmodified test under 36 busy-loop processes on 12 cores: the instrumented runs never printed their output because the machine was shutting down, so I have no load result for the old code.
  • Patched test: see the comment below. The machine was shutting down, so this is a draft until the 5× loop and a run under load are done.
  • ruff check: clean.

…od step

goto's settle is a quiet window (no API slot or response for 2 s), not
'all page requests answered'. Under the image flood the interceptor can
stay quiet that long, so goto may return before all 12 API answers reach
the page (v3.2.0 release run: title '0'). Wait for document.title to
reach N_API while the step is still active, then end it; every other
assertion is unchanged.
@tunjayoff

Copy link
Copy Markdown
Owner Author

Patched test, local run: 1 passed (169 s wall in total) while 36 busy-loop processes ran on 12 cores (load average about 40), including the elapsed < 80 check. The 5× loop on an idle machine is still to do; the machine is shutting down. ruff check is clean.

@tunjayoff
tunjayoff marked this pull request as ready for review November 21, 2026 07:14
@tunjayoff

Copy link
Copy Markdown
Owner Author

Idle machine: 5/5 passed (≈11.8 s each). ruff format reports the file was already unformatted on main; CI does not enforce ruff format, so no change here.

@tunjayoff
tunjayoff merged commit b0e35a1 into main Nov 21, 2026
8 checks passed
@tunjayoff
tunjayoff deleted the test/explorer-flood-flake branch November 21, 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