test(e2e): deterministically wait for event stream in logout propagation test (#38535)

The test raced the server-side SSE channel registration: a logout
emitted before registration is silently dropped ([example
flake](https://github.com/go-gitea/gitea/actions/runs/29699349255/job/88225654080)).
The 500ms wait from https://github.com/go-gitea/gitea/pull/37403 only
made this unlikely.

The server now registers the channel before sending the initial response
bytes, so an open connection implies registration. The shared worker
forwards the built-in `open` event (replaying it to late-attaching ports
via `EventSource.readyState`), the page exposes it as a
`data-user-events-connected` attribute, and the test waits for that
attribute instead of a fixed timeout.
This commit is contained in:
silverwind
2026-07-20 08:44:53 +00:00
committed by GitHub
parent 173965f66b
commit f9819dbb74
4 changed files with 14 additions and 7 deletions
+3 -6
View File
@@ -66,12 +66,9 @@ test.describe('events', () => {
// Verify page2 is logged in
await expect(page2.getByRole('link', {name: 'Sign In'})).toBeHidden();
// Give page2's SharedWorker time to register its SSE connection on the
// server — otherwise the logout event can race the connection and be
// silently dropped. See https://github.com/go-gitea/gitea/pull/37403
// In the future, we can set an attribute to HTML page when the connection is established,
// then here we can just wait for that attribute (it should also work for the planned WebSocket SharedWorker)
await page2.waitForTimeout(500); // eslint-disable-line playwright/no-wait-for-timeout
// Wait until the server has registered page2's event stream, otherwise the logout
// event can race the connection and be silently dropped.
await expect(page2.locator('html[data-user-events-connected]')).toBeAttached();
// Logout from page1 — this sends a logout event to all tabs
await page1.goto('/user/logout');