fix(web): fail operations on a hung page at their timeout, not the test timeout

Merged
OK
2mo ago
+662-96

A web test on a page whose script never yields (a button that starts while (true) {}) waited for the whole test timeout instead of failing at actionTimeout.

  • Root cause: guard and AttemptSession.run only raced the attempt signal, so the operation's timeoutMs was enforced by Playwright alone. On a renderer stuck in a script, Playwright never answers an evaluate (locate runs one, with no timeout) or a mouse or keyboard call, and while a trace records (the local default) even click({ timeout }) and goto({ timeout }) stay pending past their timeout.
  • Fix: every guarded operation now runs under its budget's deadline (withOperationDeadline, packages/web/src/operation-budget.ts) and fails as OPERATION_TIMEOUT (ACTION_FAILED in the report). Playwright gets a timeout 250 ms shorter, so when it can answer, its classified error (NOT_ACTIONABLE ... intercepts pointer events, ACTION_MAY_HAVE_COMMITTED) still arrives first.
  • A tap, point action, or keystroke the deadline cut off is ACTION_MAY_HAVE_COMMITTED, not a plain timeout: the input may have landed, so replay hands off as action-uncertain instead of repeating it.
  • waitForDownload runs the test's trigger, so the deadline does not cut it: the waiter keeps its full timeout and the no download started within <n>ms message names it.
  • e2e: with locate bounded, a read that starts with under 100 ms of a wait left can time out because the wait did. Such a cut-off read, after one that completed, now ends the wait on its last sample (cutOffAtDeadline, packages/e2e/src/internal/time.ts): a missing locator stays LOCATOR_NOT_FOUND, a missing frame keeps its reason, an assertion keeps ASSERTION_FAILED, each with the timeout as cause. A read that started with more budget and still timed out hung, and stays ACTION_FAILED; a negation never passes on it. docs/reference/engine.mdx says so.
  • expect(browser) matchers (toHaveURL, toHaveTitle, toHaveClass) read within the assertion's remaining budget instead of the action timeout, and report their last sample, so on a frozen page they end at their own timeout. hung-page.test.ts covers it.
  • app.open() to a server that never answers was already bounded by Playwright's goto timeout. Its documented budget is config.timeout (docs/reference/app.mdx), which by default equals the test timeout, so it still ends at the test timeout by design. It now reports the navigation's ACTION_FAILED rather than TEST_TIMEOUT, and 5 s sooner.

Tests: packages/web/tests/integration/hung-page.test.ts (locate, point tap, traced tap, traced navigation on a frozen page fail on main with "still pending"; each call must also take its whole budget; a covered button keeps NOT_ACTIONABLE, which fails if the 250 ms lead is removed), time.test.ts and locator-engine.test.ts cases for the cut-off rule (a hung read stays a failure and a negation does not pass on it; mutation-checked), and a failure-evidence.test.ts case.

Verified

Ran it locally: yes

  • testbed, built CLI, a scratch test (not committed) that serves a never-answering URL and a page whose button runs while (true) {}, each test { timeout: 60_000 }:
test('opens a server that never answers', { timeout: 60_000 }, async ({ app }) => {
  await app.open(`${origin}/never`);
});

test('taps a button that freezes the page', { timeout: 60_000 }, async ({ app, screen }) => {
  await app.open(`${origin}/`);
  await screen.getByRole('button', { name: 'Freeze' }).tap();
});
configtestmainthis branch
testbed default (actionTimeout 30 s, timeout 120 s)tap on frozen page70.0 s, TEST_TIMEOUT35.1 s, ACTION_FAILED (tap step 30.0 s)
testbed defaultopen never-answering server70.1 s, TEST_TIMEOUT64.9 s, ACTION_FAILED (open step 59.8 s)
actionTimeout: 5_000, timeout: 10_000tap on frozen page70.0 s, TEST_TIMEOUT10.1 s, ACTION_FAILED (tap step 5.0 s)
actionTimeout: 5_000, timeout: 10_000open never-answering server20.1 s, ACTION_FAILED (open step 10.1 s)14.9 s, ACTION_FAILED (open step 9.8 s)
actionTimeout: 5_000, timeout: 10_000not.toBeVisible({ timeout: 3_000 }) after freezingnot run on main9.2 s, ACTION_FAILED (assertion step 3.0 s)

The rest of each attempt after the failing step is the 5 s failure-evidence look.

main:

   × opens a server that never answers (timed-out) 70.13s
     → test timed out after 60000 ms in phase body
   × taps a button that freezes the page (timed-out) 70.02s
     → test timed out after 60000 ms in phase body

this branch:

   × opens a server that never answers 64.88s
     → operation timed out
   × taps a button that freezes the page 35.07s
     → tap timed out before the page answered; its input may have been dispatch…