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

Function TestDispatchLeave

server/session_test.go:334–382  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

332}
333
334func TestDispatchLeave(t *testing.T) {
335 uid := types.Uid(1)
336 s := test_makeSession(uid)
337 wg := sync.WaitGroup{}
338 r := responses{}
339 wg.Add(1)
340 go s.testWriteLoop(&r, &wg)
341
342 destUid := types.Uid(2)
343 topicName := uid.P2PName(destUid)
344 leave := make(chan *ClientComMessage, 1)
345 s.subs = make(map[string]*Subscription)
346 s.subs[topicName] = &Subscription{
347 done: leave,
348 }
349
350 msg := &ClientComMessage{
351 Leave: &MsgClientLeave{
352 Id: "123",
353 Topic: destUid.UserId(),
354 },
355 }
356
357 s.dispatch(msg)
358 close(s.send)
359 wg.Wait()
360
361 // Check we've routed the join request via the leave channel.
362 if len(r.messages) != 0 {
363 t.Errorf("responses: expected 0, received %d.", len(r.messages))
364 }
365 if len(leave) == 1 {
366 req := <-leave
367 if req.sess != s {
368 t.Error("Leave request: sess field expected to be the session under test.")
369 }
370 if req != msg {
371 t.Error("Leave request: leave message expected to be the original leave message.")
372 }
373 // leave request handler is expected to clean up subs.
374 s.delSub(topicName)
375 } else {
376 t.Errorf("Unsub messages: expected 1, received %d.", len(leave))
377 }
378 if len(s.subs) != 0 {
379 t.Errorf("Session subs: expected to be empty, actual size: %d", len(s.subs))
380 }
381 s.inflightReqs.Done()
382}
383
384func TestDispatchLeaveUnsubMe(t *testing.T) {
385 uid := types.Uid(1)

Callers

nothing calls this directly

Calls 11

UidTypeAlias · 0.92
test_makeSessionFunction · 0.85
testWriteLoopMethod · 0.80
P2PNameMethod · 0.80
UserIdMethod · 0.80
dispatchMethod · 0.80
WaitMethod · 0.80
ErrorMethod · 0.80
delSubMethod · 0.80
DoneMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…