MCPcopy Index your code
hub / github.com/tinode/chat / TestUnregisterSessionInactiveTopic

Function TestUnregisterSessionInactiveTopic

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

Source from the content-addressed store, hash-verified

2209}
2210
2211func TestUnregisterSessionInactiveTopic(t *testing.T) {
2212 topicName := "usrMe"
2213 numUsers := 1
2214 helper := TopicTestHelper{}
2215 helper.setUp(t, numUsers, types.TopicCatMe, topicName, true)
2216 defer helper.tearDown()
2217
2218 uid := helper.uids[0]
2219
2220 // Initial online and attach session counts.
2221 if len(helper.topic.sessions) != 1 {
2222 helper.finish()
2223 t.Fatalf("Initially attached sessions: expected 1 vs found %d", len(helper.topic.sessions))
2224 }
2225 if online := helper.topic.perUser[uid].online; online != 1 {
2226 t.Errorf("Number of online sessions: expected 1 vs found %d", online)
2227 }
2228
2229 s := helper.sessions[0]
2230 r := helper.results[0]
2231 leave := &ClientComMessage{
2232 Leave: &MsgClientLeave{
2233 Id: "id456",
2234 Topic: topicName,
2235 },
2236 AsUser: uid.UserId(),
2237 sess: s,
2238 init: true,
2239 }
2240
2241 // Deactivate topic.
2242 helper.topic.markDeleted()
2243
2244 helper.topic.unregisterSession(leave)
2245 helper.finish()
2246
2247 // Check for errors from testHubLoop
2248 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
2249 t.Fatal(errorMsgs[0].Ctrl.Text)
2250 }
2251
2252 if len(helper.topic.sessions) != 1 {
2253 t.Errorf("Attached sessions: expected 1, found %d", len(helper.topic.sessions))
2254 }
2255 if len(s.subs) != 0 {
2256 t.Errorf("Session subscriptions: expected 0, found %d", len(s.subs))
2257 }
2258 if online := helper.topic.perUser[uid].online; online != 1 {
2259 t.Errorf("Number of online sessions after unregistering: expected 1, found %d", online)
2260 }
2261 // Session output.
2262 registerSessionVerifyOutputs(t, r, []int{http.StatusServiceUnavailable})
2263 // Presence notifications.
2264 if len(helper.hubMessages) != 0 {
2265 t.Errorf("Hub isn't expected to receive any messages, received %d", len(helper.hubMessages))
2266 }
2267}
2268

Callers

nothing calls this directly

Calls 7

setUpMethod · 0.95
tearDownMethod · 0.95
finishMethod · 0.95
UserIdMethod · 0.80
markDeletedMethod · 0.80
unregisterSessionMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…