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

Function TestDispatchSet

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

Source from the content-addressed store, hash-verified

683}
684
685func TestDispatchSet(t *testing.T) {
686 uid := types.Uid(1)
687 s := test_makeSession(uid)
688 wg := sync.WaitGroup{}
689 r := responses{}
690 wg.Add(1)
691 go s.testWriteLoop(&r, &wg)
692
693 destUid := types.Uid(2)
694 topicName := uid.P2PName(destUid)
695
696 meta := make(chan *ClientComMessage, 1)
697 s.subs = make(map[string]*Subscription)
698 s.subs[topicName] = &Subscription{
699 meta: meta,
700 }
701
702 msg := &ClientComMessage{
703 Set: &MsgClientSet{
704 Id: "123",
705 Topic: destUid.UserId(),
706 MsgSetQuery: MsgSetQuery{
707 Desc: &MsgSetDesc{},
708 Sub: &MsgSetSub{},
709 Tags: []string{"abc"},
710 Cred: &MsgCredClient{},
711 },
712 },
713 }
714
715 s.dispatch(msg)
716 close(s.send)
717 wg.Wait()
718
719 // Check we've routed the join request via the meta channel.
720 if len(r.messages) != 0 {
721 t.Errorf("responses: expected 0, received %d.", len(r.messages))
722 }
723 if len(meta) == 1 {
724 req := <-meta
725 if req.sess != s {
726 t.Error("Set request: sess field expected to be the session under test.")
727 }
728 expectedWhat := constMsgMetaDesc | constMsgMetaSub | constMsgMetaTags | constMsgMetaCred
729 if msg.MetaWhat != expectedWhat {
730 t.Errorf("Set request what: expected %d vs %d", expectedWhat, msg.MetaWhat)
731 }
732 } else {
733 t.Errorf("Set messages: expected 1, received %d.", len(meta))
734 }
735}
736
737func TestDispatchSetMalformedWhat(t *testing.T) {
738 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…