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

Function TestUnregisterSessionWithPendingCall

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

Source from the content-addressed store, hash-verified

3082}
3083
3084func TestUnregisterSessionWithPendingCall(t *testing.T) {
3085 numUsers := 2
3086 helper := TopicTestHelper{}
3087 helper.setUp(t, numUsers, types.TopicCatP2P, "p2p-test", true)
3088 defer helper.tearDown()
3089
3090 uid := helper.uids[0]
3091 s := helper.sessions[0]
3092 r := helper.results[0]
3093
3094 // Set up a pending call matching the actual videoCall structure
3095 helper.topic.currentCall = &videoCall{
3096 seq: 123,
3097 parties: make(map[string]callPartyData),
3098 }
3099 helper.topic.currentCall.parties[s.sid] = callPartyData{
3100 uid: uid,
3101 isOriginator: true,
3102 sess: s,
3103 }
3104 helper.mm.EXPECT().Save(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, true)
3105
3106 leave := &ClientComMessage{
3107 Leave: &MsgClientLeave{
3108 Id: "id456",
3109 Topic: "p2p-test",
3110 },
3111 AsUser: uid.UserId(),
3112 sess: s,
3113 init: true,
3114 }
3115
3116 helper.topic.unregisterSession(leave)
3117 helper.finish()
3118
3119 // Check for errors from testHubLoop
3120 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
3121 t.Fatal(errorMsgs[0].Ctrl.Text)
3122 }
3123
3124 // Verify session was unregistered
3125 if len(helper.topic.sessions) != 1 {
3126 t.Errorf("Attached sessions: expected 1, found %d", len(helper.topic.sessions))
3127 }
3128 if len(s.subs) != 0 {
3129 t.Errorf("Session subscriptions: expected 0, found %d", len(s.subs))
3130 }
3131
3132 // Verify call party was removed (if the implementation handles this)
3133 if helper.topic.currentCall != nil && helper.topic.currentCall.parties != nil {
3134 if _, exists := helper.topic.currentCall.parties[s.sid]; exists {
3135 t.Error("Call party should have been removed when session unregistered")
3136 }
3137 }
3138
3139 if len(r.messages) != 3 {
3140 t.Fatalf("`responses` expected to contain 3 elements, found %d", len(r.messages))
3141 }

Callers

nothing calls this directly

Calls 8

setUpMethod · 0.95
tearDownMethod · 0.95
finishMethod · 0.95
UserIdMethod · 0.80
unregisterSessionMethod · 0.80
ErrorMethod · 0.80
SaveMethod · 0.65
EXPECTMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…