Skip to content

Conversation

@talissoncosta
Copy link
Contributor

@talissoncosta talissoncosta commented Feb 3, 2026

Summary

This PR fixes critical issues preventing E2E tests from running reliably locally. All 10 tests now pass consistently (100% pass rate).

Problems Fixed

1. Database Deadlock (Backend) 🔴 BLOCKER

File: api/e2etests/e2e_seed_data.py

Problem: Concurrent teardown operations caused PostgreSQL deadlocks:

  • run-with-retry.ts calling manual teardown after test failure
  • globalSetup.playwright.ts calling automatic teardown before retry runs

Solution: Added PostgreSQL advisory locks to serialise teardown/seed operations.

2. Edge API Configuration (Frontend) 🔴 BLOCKER

File: frontend/env/project_e2e.js

Problem: E2E environment configured to call external production Edge API (https://edge.api.flagsmith.com/api/v1/), unreachable from Docker, causing 6 test failures.

Solution: Changed to local Docker API (http://flagsmith-api:8000/api/v1/).

3. Redundant Teardown (Frontend) 🟡 RACE CONDITION

File: frontend/e2e/run-with-retry.ts

Problem: Manual teardown call after test failure created race conditions with Playwright's automatic teardown.

Solution: Removed redundant manual teardown, relying on Playwright's lifecycle.

Test Results

Before Fixes

  • 4/10 tests passing (40%)
  • Database deadlock errors
  • Network errors to edge.api.flagsmith.com
  • 401 auth errors

After Fixes

  • 10/10 tests passing (100%) ✅
  • Zero deadlock errors ✅
  • No network errors ✅
  • Test duration: ~2.6 minutes ✅

Passing Tests

✓ 1 [firefox] › Signup › Create Organisation and Project @oss (12.2s)
✓ 2 [firefox] › Flag Tests › test description @oss (1.1m)
✓ 3 [firefox] › Environment Tests › test description @oss (10.4s)
✓ 4 [firefox] › Invite Tests › test description @oss (11.4s)
✓ 5 [firefox] › Organisation Tests › test description @oss (11.6s)
✓ 6 [firefox] › Project Tests › test description @oss (11.2s)
✓ 7 [firefox] › Segment test 1 - multivariate flags @oss (55.0s)
✓ 8 [firefox] › Segment test 2 - priority and overrides @oss (1.2m)
✓ 9 [firefox] › Segment test 3 - user-specific overrides @oss (38.7s)
✓ 10 [firefox] › Versioning tests - versions @oss (1.2m)

  10 passed (2.6m)

Technical Details

See E2E-TEST-FIXES-COMPLETE.md for complete technical explanation.

Running Tests Locally

cd frontend
make test opts="--grep @oss"

Context

This PR is based on #6562 (Playwright migration) and addresses issues discovered during local testing. These fixes are essential for the migration to be production-ready.

🤖 Generated with Claude Code

This commit fixes critical issues preventing E2E tests from running reliably locally:

## 1. Database Deadlock Fix (Backend)

**File:** api/e2etests/e2e_seed_data.py

**Problem:** Concurrent teardown operations caused PostgreSQL deadlocks. Two separate mechanisms were calling teardown simultaneously:
- run-with-retry.ts calling manual teardown after test failure
- globalSetup.playwright.ts calling automatic teardown before retry runs

**Solution:** Added PostgreSQL advisory locks to serialise teardown/seed operations, preventing concurrent execution and database conflicts.

## 2. Edge API Configuration Fix (Frontend)

**File:** frontend/env/project_e2e.js

**Problem:** E2E environment was configured to call external production Edge API (https://edge.api.flagsmith.com/api/v1/), which is unreachable from Docker containers, causing network errors and 6 test failures.

**Solution:** Changed API endpoints to local Docker API (http://flagsmith-api:8000/api/v1/).

## 3. Redundant Teardown Removal (Frontend)

**File:** frontend/e2e/run-with-retry.ts

**Problem:** Manual teardown call after test failure created race conditions with Playwright's automatic global setup teardown.

**Solution:** Removed redundant manual teardown call, relying solely on Playwright's built-in lifecycle.

## 4. E2E Token Configuration (Infrastructure)

**File:** frontend/docker-compose-e2e-tests.yml

**Problem:** Missing E2E_TEST_TOKEN caused 401 errors from teardown endpoint. Backend expects E2E_TEST_TOKEN but only E2E_TEST_TOKEN_DEV was configured.

**Solution:** Added E2E_TEST_TOKEN environment variable to frontend service.

## Test Results

- **Before:** 4/10 tests passing (40%)
- **After:** 10/10 tests passing (100%)
- **Duration:** ~2.6 minutes
- **Deadlock errors:** Zero

See E2E-TEST-FIXES-COMPLETE.md for complete technical details.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@talissoncosta talissoncosta requested review from a team as code owners February 3, 2026 11:47
@talissoncosta talissoncosta requested review from emyller and kyle-ssg and removed request for a team February 3, 2026 11:47
@vercel
Copy link

vercel bot commented Feb 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Ready Ready Preview, Comment Feb 3, 2026 0:06am
flagsmith-frontend-staging Ready Ready Preview, Comment Feb 3, 2026 0:06am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Feb 3, 2026 0:06am

Request Review

@github-actions github-actions bot added front-end Issue related to the React Front End Dashboard api Issue related to the REST API fix labels Feb 3, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-6648 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-6648 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-6648 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-6648 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-6648 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-6648 Finished ✅ Results

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

Playwright Test Results (private-cloud)

Details

stats  0 tests across 0 suites
duration  unknown
commit  20bfd43
info  📦 Artifacts: View test results and HTML report

🖥️ Runner: depot-ubuntu-latest-16
🔄 Run: #14706 (attempt 1)
📋 Test Type: private-cloud

@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.15%. Comparing base (de21cd9) to head (f4d6d40).
⚠️ Report is 27 commits behind head on chore/playwright.

Additional details and impacted files
@@                 Coverage Diff                  @@
##           chore/playwright    #6648      +/-   ##
====================================================
- Coverage             98.18%   98.15%   -0.03%     
====================================================
  Files                  1295     1293       -2     
  Lines                 46968    46610     -358     
====================================================
- Hits                  46115    45751     -364     
- Misses                  853      859       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The Makefile change was environment-specific for Colima and is not needed
when using Docker Desktop (which has Compose V2 plugin built-in).

Updated documentation to reflect 4 essential fixes instead of 5.
E2E_TEST_TOKEN_DEV is sufficient as the teardown logic uses fallback:
- First tries E2E_TEST_TOKEN
- Falls back to E2E_TEST_TOKEN_DEV when env is 'dev'

This change reduces to 3 essential fixes only.
@talissoncosta talissoncosta force-pushed the fix/e2e-tests-deadlock-and-api branch from d39f930 to 20bfd43 Compare February 3, 2026 12:04
@github-actions github-actions bot added fix and removed fix labels Feb 3, 2026
flagsmithClientAPI: 'http://flagsmith-api:8000/api/v1/',

flagsmithClientEdgeAPI: 'https://edge.api.flagsmith.com/api/v1/',
flagsmithClientEdgeAPI: 'http://flagsmith-api:8000/api/v1/',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary ?

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

Labels

api Issue related to the REST API fix front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants