mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-03 18:24:29 +00:00
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:
@@ -38,7 +38,6 @@ func Events(ctx *context.Context) {
|
||||
|
||||
// Listen to connection close and un-register messageChan
|
||||
notify := ctx.Done()
|
||||
ctx.Resp.Flush()
|
||||
|
||||
shutdownCtx := graceful.GetManager().ShutdownContext()
|
||||
|
||||
@@ -57,11 +56,14 @@ func Events(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// send the initial response bytes only after registering messageChan, so a client whose
|
||||
// connection is open can rely on receiving all subsequent events
|
||||
if _, err := ctx.Resp.Write([]byte("\n")); err != nil {
|
||||
log.Error("Unable to write to EventStream: %v", err)
|
||||
unregister()
|
||||
return
|
||||
}
|
||||
ctx.Resp.Flush()
|
||||
|
||||
timer := time.NewTicker(30 * time.Second)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user