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

Function TestDispatchNote

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

Source from the content-addressed store, hash-verified

933}
934
935func TestDispatchNote(t *testing.T) {
936 uid := types.Uid(1)
937 s := test_makeSession(uid)
938 wg := sync.WaitGroup{}
939 r := responses{}
940 wg.Add(1)
941 go s.testWriteLoop(&r, &wg)
942
943 destUid := types.Uid(2)
944 topicName := uid.P2PName(destUid)
945
946 brdcst := make(chan *ClientComMessage, 1)
947 s.subs = make(map[string]*Subscription)
948 s.subs[topicName] = &Subscription{
949 broadcast: brdcst,
950 }
951
952 msg := &ClientComMessage{
953 Note: &MsgClientNote{
954 Topic: destUid.UserId(),
955 What: "recv",
956 SeqId: 5,
957 },
958 }
959
960 s.dispatch(msg)
961 close(s.send)
962 wg.Wait()
963
964 // Check we've routed the join request via the broadcast channel.
965 if len(r.messages) != 0 {
966 t.Errorf("responses: expected 0, received %d.", len(r.messages))
967 }
968 if len(brdcst) == 1 {
969 req := <-brdcst
970 if req.sess != s {
971 t.Error("Pub request: sess field expected to be the session under test.")
972 }
973 if req.Note.What != msg.Note.What {
974 t.Errorf("Note request what: expected '%s' vs '%s'.", msg.Note.What, req.Note.What)
975 }
976 if req.Note.SeqId != msg.Note.SeqId {
977 t.Errorf("Note request seqId: expected %d vs %d.", msg.Note.SeqId, req.Note.SeqId)
978 }
979 if req.Note.Topic != destUid.UserId() {
980 t.Errorf("Note request topic: expected '%s' vs '%s'.", destUid.UserId(), req.Note.Topic)
981 }
982 } else {
983 t.Errorf("Note messages: expected 1, received %d.", len(brdcst))
984 }
985}
986
987func TestDispatchNoteBroadcastChanFull(t *testing.T) {
988 uid := types.Uid(1)

Callers

nothing calls this directly

Calls 9

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
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…