Skip to content

fix: retry flaky Playwright integration/e2e tests on CI - #1289

Merged
miohtama merged 1 commit into
masterfrom
fix/flaky-integration-test-retries
Jun 25, 2026
Merged

fix: retry flaky Playwright integration/e2e tests on CI#1289
miohtama merged 1 commit into
masterfrom
fix/flaky-integration-test-retries

Conversation

@miohtama

Copy link
Copy Markdown
Contributor

Why

PR #1288's CI repeatedly failed on 3 tests in tests/integration/trading-view/vaults/datasets.test.ts (the vault-datasets API-key flow) — a different overlapping subset each run — while they pass reliably locally. This is long-standing: the CI workflow itself notes (since 2023) that the integration suite is "too flaky and do not pass on CI at all", and build's needs: test is commented out because of it.

Root cause (reproduced, not guessed): the integration suite drives the whole app against a single-process vite preview server whose APIs are served by an in-process mock middleware (vite-plugin-mock-dev-server). Under the parallel-worker load CI applies, that shared server intermittently mishandles a request. The captured failure snapshot shows the form displaying "The API key is not valid" after submitting the valid key — i.e. the mock returned 401 for a correct key under contention. It's environmental, not an app bug.

Reproduced locally by running the file under --workers=4 --repeat-each=8: 7/176 runs failed with the exact CI symptom. Re-running the identical stress with --retries=2: 0 hard failures (all flakes self-recovered).

The integration/e2e Playwright configs had no retries set, so CI ran with 0 retries — any single transient blip failed the whole job.

Lessons learnt

  • The integration harness shares one preview+mock process across all Playwright workers. Parallel load causes occasional request mishandling (here: a valid API key mock-rejected with 401). Treat integration/e2e flakiness on CI as environmental contention first; reproduce with --workers=N --repeat-each=M before suspecting app code.
  • Retries are the standard mitigation for inherently flaky server-backed e2e/integration suites — but only on CI. Keep retries at 0 locally so genuine regressions surface immediately instead of being masked.
  • The failure surfaces as either a 5s assertion timeout or a spurious "API key not valid" error — both trace back to the same shared-server contention, so a deterministic waitForResponse in the test would not have fixed the 401 case; retrying does.
  • If the flakiness needs eliminating at the source later, the lever is reducing contention (e.g. fewer integration workers) or a more concurrency-robust mock, not the app.

Summary

  • Added a shared ciRetries constant in tests/helpers.ts (process.env.CI ? 2 : 0) with a comment documenting the root cause.
  • Wired retries: ciRetries into all three Playwright configs: tests/integration/playwright.config.ts, tests/integration/private.playwright.config.ts, and tests/e2e/playwright.config.ts.
  • No app/source changes — test-infrastructure only.

🤖 Generated with Claude Code

The integration suite drives the whole app against a single-process
`vite preview` server with mock APIs served in-process. Under CI's
parallel worker load the shared server intermittently mishandles a
request — e.g. the vault-datasets API-key mock rejecting a *valid* key
under contention — producing spurious failures unrelated to any code
change. Reproduced locally under `--workers=4` stress (~4% per-test).

Add `retries: process.env.CI ? 2 : 0` (shared `ciRetries` helper) so
these transient blips self-recover on CI, while keeping 0 retries
locally so real failures surface immediately. Validated: the same
stress that failed 7/176 runs passes cleanly with retries enabled.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@miohtama
miohtama merged commit 1425682 into master Jun 25, 2026
5 checks passed
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