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

Function TestHandleBroadcastDataInactiveTopic

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

Source from the content-addressed store, hash-verified

604}
605
606func TestHandleBroadcastDataInactiveTopic(t *testing.T) {
607 numUsers := 2
608 helper := TopicTestHelper{}
609 helper.setUp(t, numUsers, types.TopicCatP2P, "p2p-test", true)
610 defer helper.tearDown()
611
612 // Make test message.
613 from := helper.uids[0].UserId()
614 msg := &ClientComMessage{
615 AsUser: from,
616 Pub: &MsgClientPub{
617 Topic: "p2p",
618 Content: "test",
619 },
620 sess: helper.sessions[0],
621 }
622
623 // Deactivate topic.
624 helper.topic.markDeleted()
625
626 helper.topic.handleClientMsg(msg)
627 helper.finish()
628
629 // Check for errors from testHubLoop
630 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
631 t.Fatal(errorMsgs[0].Ctrl.Text)
632 }
633
634 // Message uid1 -> uid2.
635 if len(helper.results[0].messages) == 1 {
636 em := helper.results[0].messages[0].(*ServerComMessage)
637 if em.Ctrl == nil {
638 t.Fatal("User 1 is expected to receive a ctrl message")
639 }
640 if em.Ctrl.Code < 500 || em.Ctrl.Code >= 600 {
641 t.Errorf("User1: expected ctrl.code 5xx, received %d", em.Ctrl.Code)
642 }
643 } else {
644 t.Errorf("User 1 is expected to receive one message vs %d received.", len(helper.results[0].messages))
645 }
646 if len(helper.results[1].messages) != 0 {
647 t.Errorf("User 2 is not expected to receive any messages, %d received.", len(helper.results[1].messages))
648 }
649 // Checking presence messages routed through hubhelper.
650 if len(helper.hubMessages) != 0 {
651 t.Errorf("Hubhelper.route did not expect any messages, however %d received.", len(helper.hubMessages))
652 }
653}
654
655func TestHandleBroadcastInfoP2P(t *testing.T) {
656 topicName := "usrP2P"

Callers

nothing calls this directly

Calls 6

setUpMethod · 0.95
tearDownMethod · 0.95
finishMethod · 0.95
UserIdMethod · 0.80
markDeletedMethod · 0.80
handleClientMsgMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…