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

Function TestHandleBroadcastInfoP2P

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

Source from the content-addressed store, hash-verified

653}
654
655func TestHandleBroadcastInfoP2P(t *testing.T) {
656 topicName := "usrP2P"
657 numUsers := 2
658 readId := 8
659 helper := TopicTestHelper{}
660 helper.setUp(t, numUsers, types.TopicCatP2P, topicName, true)
661 defer helper.tearDown()
662 // Pretend we have 10 messages.
663 helper.topic.lastID = 10
664 // uid1 notifies uid2 that uid1 has read messages up to seqid 8.
665 from := helper.uids[0]
666 to := helper.uids[1]
667
668 helper.ss.EXPECT().Update(topicName, from, map[string]any{"ReadSeqId": readId}).Return(nil)
669
670 msg := &ClientComMessage{
671 AsUser: from.UserId(),
672 Note: &MsgClientNote{
673 Topic: to.UserId(),
674 What: "read",
675 SeqId: readId,
676 },
677 sess: helper.sessions[0],
678 }
679 helper.topic.handleClientMsg(msg)
680 helper.finish()
681
682 // Check for errors from testHubLoop
683 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
684 t.Fatal(errorMsgs[0].Ctrl.Text)
685 }
686
687 // Topic metadata.
688 if actualReadId := helper.topic.perUser[from].readID; actualReadId != readId {
689 t.Errorf("perUser[%s].readID: expected %d, found %d.", from.UserId(), readId, actualReadId)
690 }
691 // Server messages.
692 if len(helper.results[0].messages) != 0 {
693 t.Errorf("Session 0 isn't expected to receive any messages. Received %d", len(helper.results[0].messages))
694 }
695 if len(helper.results[1].messages) != 1 {
696 t.Fatalf("Session 1 is expected to receive exactly 1 message. Received %d", len(helper.results[1].messages))
697 }
698 res := helper.results[1].messages[0].(*ServerComMessage)
699 if res.Info != nil {
700 info := res.Info
701 // Topic name will be fixed (to -> from).
702 if info.Topic != from.UserId() {
703 t.Errorf("Info.Topic: expected '%s', found '%s'", to.UserId(), info.Topic)
704 }
705 if info.From != from.UserId() {
706 t.Errorf("Info.From: expected '%s', found '%s'", from.UserId(), info.From)
707 }
708 if info.What != "read" {
709 t.Errorf("Info.What: expected 'read', found '%s'", info.What)
710 }
711 if info.SeqId != readId {
712 t.Errorf("Info.SeqId: expected %d, found %d", readId, info.SeqId)

Callers

nothing calls this directly

Calls 8

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