Skip to content

Add e2e tests for server push events#36879

Merged
silverwind merged 23 commits intogo-gitea:mainfrom
silverwind:e2eevents
Mar 27, 2026
Merged

Add e2e tests for server push events#36879
silverwind merged 23 commits intogo-gitea:mainfrom
silverwind:e2eevents

Conversation

@silverwind
Copy link
Copy Markdown
Member

@silverwind silverwind commented Mar 10, 2026

Add e2e tests for the three server push features:

  • Notification count: verifies badge appears when another user creates an issue
  • Stopwatch: verifies stopwatch element is rendered when a stopwatch is active
  • Logout propagation: verifies logout in one tab triggers redirect in another

Tests are transport-agnostic in preparation for a future WebSocket migration.

Add tests for the three SSE features: notification count updates,
stopwatch events, and logout propagation across tabs.

Also extract user management helpers (apiCreateUser, apiDeleteUser,
loginUser) into the shared e2e utils and use them in register tests.

Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 10, 2026
Remove SSE-specific code (raw EventSource connections) from e2e tests
so they work with any transport (EventSource, WebSocket, etc.).

- Stopwatch test: verify DOM element instead of raw EventSource data
- Logout test: remove EventSource open probe and waitForTimeout
- Remove unnecessary 5s sleep from logoutFromWorker (session is
  already destroyed server-side before the event reaches the client)
- Reduce EVENT_SOURCE_UPDATE_TIME from 2s to 1s for faster tests
- Raise timeouts for CI (60s assertions, 120s describe)

Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
@silverwind silverwind changed the title Add e2e tests for server-sent events Add e2e tests for server push events Mar 10, 2026
Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Playwright e2e coverage around the UI’s server-push/event-stream driven behaviors (notifications, stopwatch, logout propagation) and introduces supporting e2e utilities/config tweaks to make these tests run quickly and deterministically.

Changes:

  • Add new events.test.ts covering notification badge, active stopwatch rendering, and cross-tab logout behavior.
  • Speed up event polling for e2e runs by setting ui.notification.EVENT_SOURCE_UPDATE_TIME=1s.
  • Extend e2e test utilities with admin user create/delete helpers and per-user auth headers.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
web_src/js/modules/worker.ts Simplifies worker-triggered logout redirect (removes delay + async).
tools/test-e2e.sh Sets a faster EventSource update interval for the isolated e2e server.
tests/e2e/utils.ts Adds API helpers for creating/deleting users and logging in as them.
tests/e2e/register.test.ts Refactors cleanup to reuse apiDeleteUser() helper.
tests/e2e/events.test.ts New e2e tests for notification count, stopwatch presence, and logout propagation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

- Reorder notification test to login first, then create issue, so the
  badge appearance is actually driven by server push, not SSR
- Pass baseURL to browser.newContext() so relative URLs work in the
  logout propagation test
- Add apiCreateIssue and apiStartStopwatch helpers with retry logic
- Add optional headers param to apiCreateRepo for per-user auth
- Use helpers instead of raw request.post() calls in event tests
- Rename apiBaseUrl to baseUrl as it is the general server URL
- Use env.GITEA_TEST_E2E_DOMAIN instead of hardcoded email domain

Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 10, 2026
silverwind and others added 2 commits March 10, 2026 20:01
Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
@lunny
Copy link
Copy Markdown
Member

lunny commented Mar 21, 2026

last call @go-gitea/technical-oversight-committee

Copy link
Copy Markdown
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

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

// wait for a while because other requests (eg: logout) may be in the flight

Need to handle the "logout" conflicts.

There can be 2 requests:

  1. User clicks /user/logout?redirect_to=....
  2. Worker triggers redirection to /

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 21, 2026
@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Mar 25, 2026

There can be 2 requests:
1. User clicks /user/logout?redirect_to=....
2. Worker triggers redirection to /

I don't think there can be a conflict. Here is Claude's analysis:

  1. User clicks <a href="/user/logout">
  2. beforeunload fires before the HTTP request is sent (per HTML spec)
  3. port.close() seals the port immediately
  4. Only then does the browser send GET /user/logout
  5. Only then can the server process and emit the SSE event

Maybe it's a problem in non-conformant browsers. I can add a safeguard if you really like.

silverwind and others added 2 commits March 25, 2026 21:48
- Remove 90s describe timeout, reduce assertion timeouts from 60s to 15s
- Lower EVENT_SOURCE_UPDATE_TIME from 1s to 500ms for faster event delivery
- Parallelize cleanup apiDeleteUser calls
- Remove unnecessary timeout on logout propagation assertion

Co-Authored-By: Claude (claude-opus-4-6) <noreply@anthropic.com>
- Add $(WEBPACK_DEST) dependency to test-e2e target so frontend assets
  are rebuilt when sources change
- Parallelize apiCreateRepo and loginUser in notification count test

Co-Authored-By: Claude (claude-opus-4-6) <noreply@anthropic.com>
@wxiaoguang
Copy link
Copy Markdown
Contributor

Not yet, need to refactor some legacy code

@wxiaoguang
Copy link
Copy Markdown
Contributor

``

I don't think there can be a conflict. Here is Claude's analysis:

  1. User clicks
  2. beforeunload fires before the HTTP request is sent (per HTML spec)

It is just lucky enough because I recently refactored the "logout" to a pure href by Implements OIDC RP-Initiated Logout #36724. Otherwise, the old code uses "fetch" to do logout, there was no "beforeunload" before the logout had completed.

@wxiaoguang wxiaoguang dismissed their stale review March 27, 2026 07:00

dismiss

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged labels Mar 27, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 27, 2026
@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Mar 27, 2026

I don't imagine us ever having more than 1 shared worker, would recommend a generic name. Maybe EventsSharedWorker instead of UserEventsSharedWorker.

@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented Mar 27, 2026

I don't imagine us ever having more than 1 shared worker, would recommend a generic name.

It is already a generic name, and it matches /user/events.

In the future, maybe you need WebSocketSharedWorker

image

@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Mar 27, 2026

Websocket worker would replace the current worker but I don't want to rule out having more than 1, but I think it's highly unlikely.

@wxiaoguang
Copy link
Copy Markdown
Contributor

Websocket worker would replace the current worker but I don't want to rule out having more than 1, but I think it's highly unlikely.

There is always a chance to rename it in the future if new code comes.

Slightly longer names won't harm anyone, it also help to reduce AI hallucination: they just use grep to search the code base.

@silverwind
Copy link
Copy Markdown
Member Author

Fine with me.

@silverwind silverwind merged commit de478c4 into go-gitea:main Mar 27, 2026
26 checks passed
@GiteaBot GiteaBot added this to the 1.26.0 milestone Mar 27, 2026
@silverwind silverwind deleted the e2eevents branch March 27, 2026 10:49
silverwind added a commit to silverwind/gitea that referenced this pull request Mar 27, 2026
* origin/main:
  Add e2e tests for server push events (go-gitea#36879)

# Conflicts:
#	web_src/js/features/notification.ts
#	web_src/js/features/stopwatch.ts
silverwind added a commit to silverwind/gitea that referenced this pull request Mar 28, 2026
* origin/main:
  Fix relative-time RangeError (go-gitea#37021)
  Restyle Workflow Graph (go-gitea#36912)
  Update message severity colors, fix navbar double border (go-gitea#37019)
  Clean up checkbox cursor styles (go-gitea#37016)
  add missing cron tasks to example ini (go-gitea#37012)
  Add e2e tests for server push events (go-gitea#36879)
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 30, 2026
* main: (35 commits)
  Correct swagger annotations for enums, status codes, and notification state (go-gitea#37030)
  Update Nix flake (go-gitea#37024)
  Bump go and python versions in nix flake (go-gitea#37031)
  Make task list checkboxes clickable in the preview tab (go-gitea#37010)
  Add support for in_progress event in workflow_run webhook (go-gitea#36979)
  Fix various problems (go-gitea#37029)
  Update AI Contribution Policy (go-gitea#37022)
  Migrate from webpack to vite (go-gitea#37002)
  Upgrade yaml (go-gitea#37015)
  Fix issue label deletion with Actions tokens (go-gitea#37013)
  Hide delete branch or tag buttons in mirror or archived repositories. (go-gitea#37006)
  Update AGENTS.md with additional guidelines (go-gitea#37018)
  Optimize 'refreshAccesses' to perform update without removing then adding (go-gitea#35702)
  Fix relative-time RangeError (go-gitea#37021)
  Restyle Workflow Graph (go-gitea#36912)
  Update message severity colors, fix navbar double border (go-gitea#37019)
  Clean up checkbox cursor styles (go-gitea#37016)
  add missing cron tasks to example ini (go-gitea#37012)
  Add e2e tests for server push events (go-gitea#36879)
  Update JS dependencies (go-gitea#37001)
  ...
silverwind added a commit to silverwind/gitea that referenced this pull request Mar 30, 2026
* origin/main: (69 commits)
  Correct swagger annotations for enums, status codes, and notification state (go-gitea#37030)
  Update Nix flake (go-gitea#37024)
  Bump go and python versions in nix flake (go-gitea#37031)
  Make task list checkboxes clickable in the preview tab (go-gitea#37010)
  Add support for in_progress event in workflow_run webhook (go-gitea#36979)
  Fix various problems (go-gitea#37029)
  Update AI Contribution Policy (go-gitea#37022)
  Migrate from webpack to vite (go-gitea#37002)
  Upgrade yaml (go-gitea#37015)
  Fix issue label deletion with Actions tokens (go-gitea#37013)
  Hide delete branch or tag buttons in mirror or archived repositories. (go-gitea#37006)
  Update AGENTS.md with additional guidelines (go-gitea#37018)
  Optimize 'refreshAccesses' to perform update without removing then adding (go-gitea#35702)
  Fix relative-time RangeError (go-gitea#37021)
  Restyle Workflow Graph (go-gitea#36912)
  Update message severity colors, fix navbar double border (go-gitea#37019)
  Clean up checkbox cursor styles (go-gitea#37016)
  add missing cron tasks to example ini (go-gitea#37012)
  Add e2e tests for server push events (go-gitea#36879)
  Update JS dependencies (go-gitea#37001)
  ...

# Conflicts:
#	package.json
#	pnpm-lock.yaml
#	tests/e2e/utils.ts
#	web_src/css/themes/theme-gitea-dark.css
#	web_src/css/themes/theme-gitea-light.css
#	web_src/js/bootstrap.ts
#	web_src/js/features/codeeditor.ts
#	web_src/js/modules/errors.test.ts
#	webpack.config.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/frontend modifies/internal type/testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants