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

Function TestRegisterSessionMetadataUpdateFails

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

Source from the content-addressed store, hash-verified

2016}
2017
2018func TestRegisterSessionMetadataUpdateFails(t *testing.T) {
2019 topicName := "grpTest"
2020 numUsers := 2
2021 helper := TopicTestHelper{}
2022 helper.setUp(t, numUsers, types.TopicCatGrp, topicName, false)
2023 defer helper.tearDown()
2024 if len(helper.topic.sessions) != 0 {
2025 helper.finish()
2026 t.Fatalf("Initially attached sessions: expected 0 vs found %d", len(helper.topic.sessions))
2027 }
2028
2029 s := helper.sessions[1]
2030 uid := helper.uids[1]
2031 r := helper.results[1]
2032
2033 pud := helper.topic.perUser[uid]
2034 pud.modeWant = types.ModeCPublic
2035 pud.modeGiven = types.ModeCPublic
2036 helper.topic.perUser[uid] = pud
2037
2038 // Want ownership.
2039 newWant := "JRWP"
2040 join := &ClientComMessage{
2041 Original: topicName,
2042 Sub: &MsgClientSub{
2043 Id: "id456",
2044 Topic: topicName,
2045 Set: &MsgSetQuery{
2046 Sub: &MsgSetSub{
2047 Mode: newWant,
2048 },
2049 },
2050 },
2051 AsUser: uid.UserId(),
2052 AuthLvl: int(auth.LevelAuth),
2053
2054 sess: s,
2055 }
2056 // DB call fails.
2057 helper.ss.EXPECT().Update(topicName, uid, gomock.Any()).Return(types.ErrInternal)
2058
2059 helper.topic.registerSession(join)
2060 helper.finish()
2061
2062 // Check for errors from testHubLoop
2063 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
2064 t.Fatal(errorMsgs[0].Ctrl.Text)
2065 }
2066
2067 if len(s.subs) != 0 {
2068 t.Errorf("Session subscriptions: expected 0, found %d", len(s.subs))
2069 }
2070 online := helper.topic.perUser[uid].online
2071 if online != 0 {
2072 t.Errorf("Number of online sessions: expected 0, found %d", online)
2073 }
2074 // Session output.
2075 registerSessionVerifyOutputs(t, r, []int{http.StatusInternalServerError})

Callers

nothing calls this directly

Calls 8

setUpMethod · 0.95
tearDownMethod · 0.95
finishMethod · 0.95
UserIdMethod · 0.80
registerSessionMethod · 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…