From f8d14b77eba55e552387bb2f0c68cba2c17f3d79 Mon Sep 17 00:00:00 2001 From: silverwind Date: Tue, 31 Mar 2026 15:59:25 +0200 Subject: [PATCH] Increase e2e test timeouts on CI to fix flaky tests (#37053) Introduce a `GITEA_TEST_E2E_TIMEOUT_FACTOR` env var (3 on CI, 1 locally, overridable) to scale Playwright e2e timeouts, fixing flaky tests like `logout propagation` that timed out waiting for SSE event propagation on slow CI runners. | Timeout | Before (local) | After (local) | Before (CI) | After (CI) | |---|---|---|---|---| | expect | 3000 | 5000 | 6000 | 15000 | | action | 3000 | 5000 | 6000 | 15000 | | test | 6000 | 10000 | 12000 | 30000 | | navigation | 6000 | 10000 | 12000 | 30000 | --- This PR was written with the help of Claude Opus 4.6 --------- Co-authored-by: Claude (Opus 4.6) --- CONTRIBUTING.md | 9 +++++---- playwright.config.ts | 10 ++++++---- tests/e2e/events.test.ts | 4 ++-- tests/e2e/utils.ts | 2 ++ tools/test-e2e.sh | 10 ++++++++++ 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 856515a34e..4b32631d6a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -198,10 +198,11 @@ Here's how to run the test suite: - E2E test environment variables -| Variable | Description | -| :------------------------ | :---------------------------------------------------------------- | -| ``GITEA_TEST_E2E_DEBUG`` | When set, show Gitea server output | -| ``GITEA_TEST_E2E_FLAGS`` | Additional flags passed to Playwright, for example ``--ui`` | +| Variable | Description | +| :-------------------------------- | :---------------------------------------------------------- | +| ``GITEA_TEST_E2E_DEBUG`` | When set, show Gitea server output | +| ``GITEA_TEST_E2E_FLAGS`` | Additional flags passed to Playwright, for example ``--ui`` | +| ``GITEA_TEST_E2E_TIMEOUT_FACTOR`` | Timeout multiplier (default: 3 on CI, 1 locally) | ## Translation diff --git a/playwright.config.ts b/playwright.config.ts index f566054f78..e318a79d0c 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,5 +1,7 @@ import {env} from 'node:process'; import {defineConfig, devices} from '@playwright/test'; +const timeoutFactor = Number(env.GITEA_TEST_E2E_TIMEOUT_FACTOR) || 1; +const timeout = 5000 * timeoutFactor; export default defineConfig({ testDir: './tests/e2e/', @@ -7,15 +9,15 @@ export default defineConfig({ testMatch: /.*\.test\.ts/, forbidOnly: Boolean(env.CI), reporter: 'list', - timeout: env.CI ? 12000 : 6000, + timeout: 2 * timeout, expect: { - timeout: env.CI ? 6000 : 3000, + timeout, }, use: { baseURL: env.GITEA_TEST_E2E_URL?.replace?.(/\/$/g, ''), locale: 'en-US', - actionTimeout: env.CI ? 6000 : 3000, - navigationTimeout: env.CI ? 12000 : 6000, + actionTimeout: timeout, + navigationTimeout: 2 * timeout, }, projects: [ { diff --git a/tests/e2e/events.test.ts b/tests/e2e/events.test.ts index 61f1a3c881..4cd46815c3 100644 --- a/tests/e2e/events.test.ts +++ b/tests/e2e/events.test.ts @@ -1,5 +1,5 @@ import {test, expect} from '@playwright/test'; -import {loginUser, baseUrl, apiUserHeaders, apiCreateUser, apiDeleteUser, apiCreateRepo, apiCreateIssue, apiStartStopwatch} from './utils.ts'; +import {loginUser, baseUrl, apiUserHeaders, apiCreateUser, apiDeleteUser, apiCreateRepo, apiCreateIssue, apiStartStopwatch, timeoutFactor} from './utils.ts'; // These tests rely on a short EVENT_SOURCE_UPDATE_TIME in the e2e server config. test.describe('events', () => { @@ -23,7 +23,7 @@ test.describe('events', () => { await apiCreateIssue(request, owner, repoName, {title: 'events notification test', headers: apiUserHeaders(commenter)}); // Wait for the notification badge to appear via server event - await expect(badge).toBeVisible({timeout: 15000}); + await expect(badge).toBeVisible({timeout: 15000 * timeoutFactor}); // Cleanup await Promise.all([apiDeleteUser(request, commenter), apiDeleteUser(request, owner)]); diff --git a/tests/e2e/utils.ts b/tests/e2e/utils.ts index 1c3b33be90..c7e6636bc2 100644 --- a/tests/e2e/utils.ts +++ b/tests/e2e/utils.ts @@ -3,6 +3,8 @@ import {env} from 'node:process'; import {expect} from '@playwright/test'; import type {APIRequestContext, Locator, Page} from '@playwright/test'; +export const timeoutFactor = Number(env.GITEA_TEST_E2E_TIMEOUT_FACTOR) || 1; + export function baseUrl() { return env.GITEA_TEST_E2E_URL?.replace(/\/$/g, ''); } diff --git a/tools/test-e2e.sh b/tools/test-e2e.sh index e11c788fdf..ed3d8c402e 100755 --- a/tools/test-e2e.sh +++ b/tools/test-e2e.sh @@ -88,10 +88,20 @@ GITEA_TEST_E2E_EMAIL="$GITEA_TEST_E2E_USER@$GITEA_TEST_E2E_DOMAIN" --must-change-password=false \ --admin +# timeout multiplier, CI runners are slower +if [ -z "${GITEA_TEST_E2E_TIMEOUT_FACTOR:-}" ]; then + if [ -n "${CI:-}" ]; then + GITEA_TEST_E2E_TIMEOUT_FACTOR=3 + else + GITEA_TEST_E2E_TIMEOUT_FACTOR=1 + fi +fi + export GITEA_TEST_E2E_URL="$E2E_URL" export GITEA_TEST_E2E_DOMAIN export GITEA_TEST_E2E_USER export GITEA_TEST_E2E_PASSWORD export GITEA_TEST_E2E_EMAIL +export GITEA_TEST_E2E_TIMEOUT_FACTOR pnpm exec playwright test "$@"