Skip to content

Make dashboard e2e tests deterministic #4341

Backlog

Description

@sentry-junior

Dashboard e2e is the main reason CI gets rerun. Each flake gets fixed with a test-side wait, and then another test starts to flake. This is the analysis of the causes. Evidence is from 0eb3febf3.

Impact (10-26 to 11-25)

  • 168 of 342 reruns that ended green (49%) had a test / dashboard e2e failure on an earlier attempt.
  • 88 of 1,324 main pushes (6.6%) had an e2e failure.
  • retries: 1 hides flakes: about 39% of recent main runs uploaded a flaky-test trace. failOnFlakyTests was added in c3cb6c9db and removed in 4759af9b3.
  • Vitest dashboard tests are not a flake source.
  • 13 recent deflake commits are waits, splits, or exemptions, for example 1e9a143a4, b204668c5, and 548f661d0. 9 are real fixes.

Causes

  • Real timers with a frozen Date. setFixedTime (e2e/harness.ts:430-434) pins only Date. The 5s /api/versions poll, the SSE stream, and the 2s and 500ms detail polls keep running. Only 7 of 76 specs control timers.
    • Request budgets count background polls (e2e/request-budget.ts:58-60).
    • 57 errors in the window are "The test ended while requests that it caused were open".
  • Query functions with side effects. The versions queryFn sets React state and starts invalidations (src/client/versions.ts:373-379). The detail queryFn invalidates side reads and Inbox lists (conversations/queries.ts:165, conversationSideReads.ts:40). One poll can start fetches that a test cannot await. The harness allows 8 background reads (e2e/harness.ts:83-103).
  • Two mock layers. There are about 306 page.route overrides on top of the in-process mock server (src/mock-reporting, about 10.5k lines).
    • Some /api reads reach real Postgres or Redis, which CI shares across workers. Each full run logs 35 api.unhandled.exception errors.
    • Mock state reset is a hand-kept list (app.ts:99-109).
    • The server runs in the Playwright worker, so CPU load slows the server and the test together.
  • Scroll and virtualization. Transcript rows use an estimated size and then a measured one. transcriptBottomPinning.ts (949 lines) settles after a double rAF or a 400ms timeout. This is the most common failure mode: 113 toBeInViewport errors. It is also visibly buggy on mobile, including the scroll to unread history.
  • Smaller races.
    • List order is held while the pointer is over the list (heldListOrder.ts:116, inbox/heldRows.ts).
    • 11 of 13 lazy Suspense sites use fallback={null}.
    • There are 24 replace: true URL writes. The current top flake is that Inbox item= never reaches the URL.
    • CI uses the runner's Chrome, which is not pinned.

Current flakes

  • inbox/code › Code · Mine sorts, and inbox-cards › image strip click: item= is missing from the URL.
  • conversations-mobile long press: fails 3 of 12 runs under CPU load.
  • question-cards mobile and inbox-item-evidence: the waiting pill count is 1 when 0 is expected.
  • navigation.spec.ts:325: fails 4 of 6 runs under load.
  • System and space-lead request budgets.

Proposed plan (from the analysis)

  1. Harness:
    • Install the fake clock in every test, and turn polls off unless a spec opts in.
    • Make the mock server use the injected browser time.
    • Fail any read that reaches a real store.
    • Remove page.route overrides.
    • Pin Chrome.
  2. Sync layer: query functions only read. One module owns the versions poll and invalidation, and gives tests a settle signal they can await. Set QueryClient defaults and query key factories in one place.
  3. Code reads time through an injectable clock and scheduler.
  4. Replace the bottom-pinning code with a virtualizer built for chat.
  5. Remove fragile behavior: pointer-held order, the 500ms quick-question poll, and hover-only fetches. Remove request-budget and viewport assertions that only test timing.
  6. Turn failOnFlakyTests back on.

The server-rendering migration that was discussed would fix none of these causes. Related: #4177, #4031, #4254.

via @dcramer.

--

View Session [Sentry]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions