perf: batch group unread fanout
This commit is contained in:
@@ -109,6 +109,60 @@ func TestRealtimeUserPresenceSkipsSessionsAttachedToTopic(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRealtimeGroupUnreadBatchPreservesDetachedMultiDeviceNotification(t *testing.T) {
|
||||
oldStore := globals.sessionStore
|
||||
defer func() { globals.sessionStore = oldStore }()
|
||||
|
||||
tenantID := types.TenantID(1)
|
||||
recipient := types.Uid(1002)
|
||||
other := types.Uid(1003)
|
||||
topic := "grpUnreadBatchTest"
|
||||
globals.sessionStore = realtimeTestSessionStore(
|
||||
realtimeTestSession("sid-attached", tenantID, recipient, topic),
|
||||
realtimeTestSession("sid-detached-1", tenantID, recipient, ""),
|
||||
realtimeTestSession("sid-detached-2", tenantID, recipient, ""),
|
||||
realtimeTestSession("sid-other", tenantID, other, ""),
|
||||
)
|
||||
payload := realtimeGroupUnreadMessage{
|
||||
Topic: topic,
|
||||
Actor: types.Uid(1001).UserId(),
|
||||
SeqID: 51,
|
||||
Recipients: []realtimeGroupUnreadRecipient{
|
||||
{User: recipient.UserId(), Source: topic},
|
||||
},
|
||||
}
|
||||
raw, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
deliverRealtimeFanoutEnvelope(&store.RealtimeFanoutEnvelope{
|
||||
TenantID: tenantID,
|
||||
Kind: realtimeKindGroupUnread,
|
||||
TargetType: realtimeTargetUsers,
|
||||
Target: topic,
|
||||
Message: raw,
|
||||
})
|
||||
|
||||
if len(globals.sessionStore.Get("sid-attached").send) != 0 {
|
||||
t.Fatal("attached session must rely on the topic data broadcast")
|
||||
}
|
||||
for _, sid := range []string{"sid-detached-1", "sid-detached-2"} {
|
||||
select {
|
||||
case got := <-globals.sessionStore.Get(sid).send:
|
||||
pres := got.(*ServerComMessage).Pres
|
||||
if pres == nil || pres.What != "msg" || pres.Src != topic || pres.SeqId != 51 || pres.SkipTopic != topic {
|
||||
t.Fatalf("%s got unexpected presence: %#v", sid, pres)
|
||||
}
|
||||
default:
|
||||
t.Fatalf("detached session %s must receive unread presence", sid)
|
||||
}
|
||||
}
|
||||
if len(globals.sessionStore.Get("sid-other").send) != 0 {
|
||||
t.Fatal("non-recipient session received unread presence")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRealtimeP2PTopicFallbackRewritesVisibleTopic(t *testing.T) {
|
||||
oldStore := globals.sessionStore
|
||||
oldHub := globals.hub
|
||||
|
||||
Reference in New Issue
Block a user