mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-31 03:14:17 +09:00
enhance(websocket): improve client synchronization (#38847)
Keep notification counts and stopwatches in sync when tabs open or reconnect, closing the gap behind [this flake](https://github.com/go-gitea/gitea/actions/runs/31312525323/job/93242429394). 1. Send current notification counts and stopwatch state on each WebSocket connection, replacing the separate state fetches tabs made on every connect. 2. Tabs joining an already open connection fetch current state once, since its snapshot went out before they attached. 3. Send events queued during the handshake before the snapshot, so older events can't roll it back. 4. Wait for the Redis SUBSCRIBE acknowledgement, so the snapshot read after subscribing can't miss an event.
This commit is contained in:
1 parent
965d7522e0
commit
7308c5fb97
20 files changed
+268
-247
No files matched your search
@@ -0,0 +1,19 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package websocket
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEventForSessionTargetsAndKeepsEmptyData(t *testing.T) {
|
||||
targeted := makeEventMessage("targeted-event", "sess-A", nil)
|
||||
assert.JSONEq(t, `{"eventType":"targeted-event"}`, string(EventForSession(targeted, "sess-A")))
|
||||
assert.Nil(t, EventForSession(targeted, "sess-B"))
|
||||
|
||||
broadcast := makeEventMessage("list-event", "", []int{})
|
||||
assert.JSONEq(t, `{"eventType":"list-event","eventData":[]}`, string(EventForSession(broadcast, "sess-A")))
|
||||
}
|
||||
Reference in new issue
Block a user