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

Function TestHandleBroadcastPresInactiveTopic

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

Source from the content-addressed store, hash-verified

1217}
1218
1219func TestHandleBroadcastPresInactiveTopic(t *testing.T) {
1220 topicName := "usrMe"
1221 numUsers := 1
1222 helper := TopicTestHelper{}
1223 helper.setUp(t, numUsers, types.TopicCatMe, topicName, true)
1224 defer helper.tearDown()
1225
1226 uid := helper.uids[0]
1227 srcUid := types.Uid(10)
1228 helper.topic.perSubs = make(map[string]perSubsData)
1229 helper.topic.perSubs[srcUid.UserId()] = perSubsData{enabled: true, online: false}
1230
1231 msg := &ServerComMessage{
1232 AsUser: uid.UserId(),
1233 RcptTo: uid.UserId(),
1234 Pres: &MsgServerPres{
1235 Topic: "me",
1236 Src: srcUid.UserId(),
1237 What: "on",
1238 },
1239 }
1240
1241 // Deactivate topic.
1242 helper.topic.markDeleted()
1243
1244 helper.topic.handleServerMsg(msg)
1245 helper.finish()
1246
1247 // Check for errors from testHubLoop
1248 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
1249 t.Fatal(errorMsgs[0].Ctrl.Text)
1250 }
1251
1252 // Topic metadata.
1253 if online := helper.topic.perSubs[srcUid.UserId()].online; online {
1254 t.Errorf("User %s is expected to be offline.", srcUid.UserId())
1255 }
1256 // Server messages.
1257 if len(helper.results[0].messages) != 0 {
1258 t.Fatalf("Session 0 is not expected to receive messages. Received %d.", len(helper.results[0].messages))
1259 }
1260 if len(helper.hubMessages) != 0 {
1261 t.Errorf("Hubhelper.route isn't expected to receive messages. Received %d", len(helper.hubMessages))
1262 }
1263}
1264
1265const (
1266 NoSub = 0

Callers

nothing calls this directly

Calls 7

setUpMethod · 0.95
tearDownMethod · 0.95
finishMethod · 0.95
UidTypeAlias · 0.92
UserIdMethod · 0.80
markDeletedMethod · 0.80
handleServerMsgMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…