fix: fan out receipts and align tenant schema

This commit is contained in:
richjohnrambo
2026-09-16 22:09:52 +08:00
parent 6729f40665
commit 0ae4af0c31
6 changed files with 314 additions and 3 deletions
+69
View File
@@ -149,6 +149,75 @@ func TestRealtimeSessionControlStaleEvictDropped(t *testing.T) {
}
}
func TestRealtimeP2PTopicFallbackRewritesVisibleInfoTopic(t *testing.T) {
oldStore := globals.sessionStore
oldHub := globals.hub
defer func() {
globals.sessionStore = oldStore
globals.hub = oldHub
}()
tenantID := types.TenantID(1)
uid1 := types.Uid(1001)
uid2 := types.Uid(1002)
topic := uid1.P2PName(uid2)
if topic == "" {
t.Fatal("failed to create p2p topic")
}
globals.hub = nil
globals.sessionStore = realtimeTestSessionStore(
realtimeTestSession("sid-u1", tenantID, uid1, uid2.UserId()),
realtimeTestSession("sid-u2", tenantID, uid2, uid1.UserId()),
)
msg := &ServerComMessage{
Info: &MsgServerInfo{Topic: topic, From: uid1.UserId(), What: "read", SeqId: 13},
}
raw, err := json.Marshal(msg)
if err != nil {
t.Fatal(err)
}
deliverRealtimeFanoutEnvelope(&store.RealtimeFanoutEnvelope{
TenantID: tenantID,
Kind: realtimeKindMessage,
TargetType: realtimeTargetTopic,
Target: topic,
Message: raw,
})
expectTopic := map[string]string{"sid-u1": uid2.UserId(), "sid-u2": uid1.UserId()}
for sid, visibleTopic := range expectTopic {
sess := globals.sessionStore.Get(sid)
select {
case got := <-sess.send:
info := got.(*ServerComMessage).Info
if info.Topic != visibleTopic {
t.Fatalf("%s got info topic %q, want %q", sid, info.Topic, visibleTopic)
}
if info.What != "read" || info.SeqId != 13 || info.From != uid1.UserId() {
t.Fatalf("%s got unexpected info %#v", sid, info)
}
default:
t.Fatalf("expected p2p info delivery to %s", sid)
}
}
}
func TestRealtimeInfoDedupKeySeparatesReadRecv(t *testing.T) {
read := realtimeMessageDedupKey("p2pABC", &ServerComMessage{
Info: &MsgServerInfo{From: "usrA", What: "read", SeqId: 12},
})
recv := realtimeMessageDedupKey("p2pABC", &ServerComMessage{
Info: &MsgServerInfo{From: "usrA", What: "recv", SeqId: 12},
})
if read == recv {
t.Fatalf("read and recv info dedup keys must differ: %q", read)
}
if read != "info:p2pABC:read:usrA::12" {
t.Fatalf("unexpected read dedup key %q", read)
}
}
func realtimeTestSessionStore(sessions ...*Session) *SessionStore {
ss := NewSessionStore(time.Minute)
for _, sess := range sessions {