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

Function TestHandleBroadcastDataDbError

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

Source from the content-addressed store, hash-verified

549}
550
551func TestHandleBroadcastDataDbError(t *testing.T) {
552 numUsers := 2
553 helper := TopicTestHelper{}
554 helper.setUp(t, numUsers, types.TopicCatP2P, "p2p-test", true)
555 defer helper.tearDown()
556
557 // DB returns an error.
558 helper.mm.EXPECT().Save(gomock.Any(), gomock.Any(), gomock.Any()).Return(types.ErrInternal, false)
559
560 // Make test message.
561 from := helper.uids[0].UserId()
562 msg := &ClientComMessage{
563 AsUser: from,
564 Pub: &MsgClientPub{
565 Topic: "p2p",
566 Content: "test",
567 },
568 sess: helper.sessions[0],
569 }
570
571 if helper.topic.lastID != 0 {
572 t.Errorf("Topic.lastID: expected 0, found %d", helper.topic.lastID)
573 }
574 helper.topic.handleClientMsg(msg)
575 helper.finish()
576
577 // Check for errors from testHubLoop
578 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
579 t.Fatal(errorMsgs[0].Ctrl.Text)
580 }
581
582 if helper.topic.lastID != 0 {
583 t.Errorf("Topic.lastID: expected to remain 0, found %d", helper.topic.lastID)
584 }
585 // Message uid1 -> uid2.
586 if len(helper.results[0].messages) == 1 {
587 em := helper.results[0].messages[0].(*ServerComMessage)
588 if em.Ctrl == nil {
589 t.Fatal("User 1 is expected to receive a ctrl message")
590 }
591 if em.Ctrl.Code < 500 || em.Ctrl.Code >= 600 {
592 t.Errorf("User1: expected ctrl.code 5xx, received %d", em.Ctrl.Code)
593 }
594 } else {
595 t.Errorf("User 1 is expected to receive one message vs %d received.", len(helper.results[0].messages))
596 }
597 if len(helper.results[1].messages) != 0 {
598 t.Errorf("User 2 is not expected to receive any messages, %d received.", len(helper.results[1].messages))
599 }
600 // Checking presence messages routed through hubhelper.
601 if len(helper.hubMessages) != 0 {
602 t.Errorf("Hubhelper.route did not expect any messages, however %d received.", len(helper.hubMessages))
603 }
604}
605
606func TestHandleBroadcastDataInactiveTopic(t *testing.T) {
607 numUsers := 2

Callers

nothing calls this directly

Calls 7

setUpMethod · 0.95
tearDownMethod · 0.95
finishMethod · 0.95
UserIdMethod · 0.80
handleClientMsgMethod · 0.80
SaveMethod · 0.65
EXPECTMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…