MCPcopy
hub / github.com/tinode/chat / TestHandleBroadcastInfoChannelProcessing

Function TestHandleBroadcastInfoChannelProcessing

server/topic_test.go:1078–1157  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1076}
1077
1078func TestHandleBroadcastInfoChannelProcessing(t *testing.T) {
1079 topicName := "grpTest"
1080 chanName := "chnTest"
1081 numUsers := 3
1082 helper := TopicTestHelper{}
1083 helper.setUp(t, numUsers, types.TopicCatGrp, topicName, true)
1084 helper.topic.isChan = true
1085 defer helper.tearDown()
1086 // Pretend we have 10 messages.
1087 helper.topic.lastID = 10
1088 // uid1 notifies uid2 that uid1 has read messages up to seqid 11.
1089 readId := 8
1090 from := helper.uids[0]
1091 for i := 1; i < numUsers; i++ {
1092 uid := helper.uids[i]
1093 pud := helper.topic.perUser[uid]
1094 pud.modeGiven = types.ModeCChnReader
1095 pud.isChan = true
1096 helper.topic.perUser[uid] = pud
1097 }
1098
1099 helper.ss.EXPECT().Update(chanName, from, map[string]any{"ReadSeqId": readId}).Return(nil)
1100
1101 msg := &ClientComMessage{
1102 AsUser: from.UserId(),
1103 Original: chanName,
1104 Note: &MsgClientNote{
1105 Topic: chanName,
1106 What: "read",
1107 SeqId: readId,
1108 },
1109 sess: helper.sessions[0],
1110 }
1111 helper.topic.handleClientMsg(msg)
1112 helper.finish()
1113
1114 // Check for errors from testHubLoop
1115 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
1116 t.Fatal(errorMsgs[0].Ctrl.Text)
1117 }
1118
1119 // Topic metadata.
1120 // We do not update read ids for channel topics.
1121 if actualReadId := helper.topic.perUser[from].readID; actualReadId != 0 {
1122 t.Errorf("perUser[%s].readID: expected 0, found %d.", from.UserId(), actualReadId)
1123 }
1124 // Server messages. Note messages aren't forwarded by channel topics.
1125 for i, r := range helper.results {
1126 if numMessages := len(r.messages); numMessages != 0 {
1127 t.Errorf("User %d is not expected to receive any messages, %d received.", i, numMessages)
1128 }
1129 }
1130
1131 // Send a pres back to the sender.
1132 if len(helper.hubMessages) != 1 {
1133 t.Fatalf("Hubhelper.route did not expect any messages, however %d received.", len(helper.hubMessages))
1134 }
1135 if mm, ok := helper.hubMessages[from.UserId()]; ok || len(mm) != 1 {

Callers

nothing calls this directly

Calls 7

setUpMethod · 0.95
tearDownMethod · 0.95
finishMethod · 0.95
UserIdMethod · 0.80
handleClientMsgMethod · 0.80
UpdateMethod · 0.65
EXPECTMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…