fix p2p topic canonicalization and stale subscriptions

This commit is contained in:
richjohnrambo
2026-09-12 00:08:30 +08:00
parent f1dfffcfb5
commit a9a4970d9f
9 changed files with 148 additions and 66 deletions
+12 -13
View File
@@ -259,8 +259,8 @@ func TestHandleBroadcastDataP2P(t *testing.T) {
if r.Data == nil {
t.Fatalf("Response[0] must have a ctrl message")
}
if r.Data.Topic != from {
t.Errorf("Response[0] topic: expected '%s', got '%s'", from, r.Data.Topic)
if r.Data.Topic != "p2p-test" {
t.Errorf("Response[0] topic: expected '%s', got '%s'", "p2p-test", r.Data.Topic)
}
if r.Data.Content.(string) != "test" {
t.Errorf("Response[0] content: expected 'test', got '%s'", r.Data.Content.(string))
@@ -274,7 +274,7 @@ func TestHandleBroadcastDataP2P(t *testing.T) {
if len(helper.hubMessages) != 2 {
t.Fatal("Huhelper.route expected exactly two recipients routed via huhelper.")
}
for i, uid := range helper.uids {
for _, uid := range helper.uids {
if mm, ok := helper.hubMessages[uid.UserId()]; ok {
if len(mm) == 1 {
s := mm[0]
@@ -286,7 +286,7 @@ func TestHandleBroadcastDataP2P(t *testing.T) {
if p.SkipTopic != "p2p-test" {
t.Errorf("Uid %s: pres skip topic is expected to be 'p2p-test', got %s", uid.UserId(), p.SkipTopic)
}
expectedSrc := helper.uids[i^1].UserId()
expectedSrc := "p2p-test"
if p.Src != expectedSrc {
t.Errorf("Uid %s: pres.src expected: %s, found: %s", uid.UserId(), expectedSrc, p.Src)
}
@@ -425,8 +425,8 @@ func TestHandleBroadcastCall(t *testing.T) {
if r.Data == nil {
t.Fatalf("Response[0] must have a ctrl message")
}
if r.Data.Topic != from {
t.Errorf("Response[0] topic: expected '%s', got '%s'", from, r.Data.Topic)
if r.Data.Topic != "p2p-test" {
t.Errorf("Response[0] topic: expected '%s', got '%s'", "p2p-test", r.Data.Topic)
}
content := r.Data.Content.(map[string]any)
if content["callId"] != "call-1" || content["callType"] != "audio" || content["video"] != false {
@@ -447,7 +447,7 @@ func TestHandleBroadcastCall(t *testing.T) {
if len(helper.hubMessages) != 2 {
t.Fatal("Huhelper.route expected exactly two recipients routed via huhelper.")
}
for i, uid := range helper.uids {
for _, uid := range helper.uids {
if mm, ok := helper.hubMessages[uid.UserId()]; ok {
if len(mm) == 1 {
s := mm[0]
@@ -459,7 +459,7 @@ func TestHandleBroadcastCall(t *testing.T) {
if p.SkipTopic != "p2p-test" {
t.Errorf("Uid %s: pres skip topic is expected to be 'p2p-test', got %s", uid.UserId(), p.SkipTopic)
}
expectedSrc := helper.uids[i^1].UserId()
expectedSrc := "p2p-test"
if p.Src != expectedSrc {
t.Errorf("Uid %s: pres.src expected: %s, found: %s", uid.UserId(), expectedSrc, p.Src)
}
@@ -1321,9 +1321,8 @@ func TestHandleBroadcastInfoP2P(t *testing.T) {
res := helper.results[1].messages[0].(*ServerComMessage)
if res.Info != nil {
info := res.Info
// Topic name will be fixed (to -> from).
if info.Topic != from.UserId() {
t.Errorf("Info.Topic: expected '%s', found '%s'", to.UserId(), info.Topic)
if info.Topic != topicName {
t.Errorf("Info.Topic: expected '%s', found '%s'", topicName, info.Topic)
}
if info.From != from.UserId() {
t.Errorf("Info.From: expected '%s', found '%s'", from.UserId(), info.From)
@@ -1341,9 +1340,9 @@ func TestHandleBroadcastInfoP2P(t *testing.T) {
if len(helper.hubMessages) != 2 {
t.Fatalf("Hubhelper.route expected exactly two recipients routed via hubhelper. Found %d", len(helper.hubMessages))
}
for i, uid := range helper.uids {
for _, uid := range helper.uids {
if routedMsgs, ok := helper.hubMessages[uid.UserId()]; ok {
expectedSrc := helper.uids[i^1].UserId()
expectedSrc := topicName
for _, s := range routedMsgs {
if s.Info != nil {
// Info messages for offline sessions.