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

Function TestRegisterSessionNewChannelGetSubDbError

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

Source from the content-addressed store, hash-verified

1731}
1732
1733func TestRegisterSessionNewChannelGetSubDbError(t *testing.T) {
1734 topicName := "grpTest"
1735 chanName := "chnTest"
1736 numUsers := 1
1737 helper := TopicTestHelper{}
1738 helper.setUp(t, numUsers, types.TopicCatGrp, topicName, false)
1739 // It is a channel.
1740 helper.topic.isChan = true
1741 defer helper.tearDown()
1742 if len(helper.topic.sessions) != 0 {
1743 helper.finish()
1744 t.Fatalf("Initially attached sessions: expected 0 vs found %d", len(helper.topic.sessions))
1745 }
1746
1747 // New uid. This should attempt to add a new subscription
1748 // which produces an error b/c authLevel isn't root.
1749 uid := types.Uid(10001)
1750 s, r := helper.newSession("test-sid", uid)
1751 helper.sessions = append(helper.sessions, s)
1752 helper.results = append(helper.results, r)
1753
1754 join := &ClientComMessage{
1755 Original: chanName,
1756 Sub: &MsgClientSub{
1757 Id: "id456",
1758 Topic: chanName,
1759 },
1760 AsUser: uid.UserId(),
1761 sess: s,
1762 }
1763
1764 helper.ss.EXPECT().Get(chanName, uid, false).Return(nil, types.ErrInternal)
1765
1766 helper.topic.registerSession(join)
1767 helper.finish()
1768
1769 // Check for errors from testHubLoop
1770 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
1771 t.Fatal(errorMsgs[0].Ctrl.Text)
1772 }
1773
1774 if len(s.subs) != 0 {
1775 t.Errorf("Session subscriptions: expected 0, found %d", len(s.subs))
1776 }
1777 online := helper.topic.perUser[uid].online
1778 if online != 0 {
1779 t.Errorf("Number of online sessions: expected 0, found %d", online)
1780 }
1781 // Session output.
1782 registerSessionVerifyOutputs(t, r, []int{http.StatusInternalServerError})
1783 // Presence notifications.
1784 if len(helper.hubMessages) != 0 {
1785 t.Errorf("Hub isn't expected to receive any messages, received %d", len(helper.hubMessages))
1786 }
1787}
1788
1789func TestRegisterSessionCreateSubFailed(t *testing.T) {
1790 topicName := "grpTest"

Callers

nothing calls this directly

Calls 10

setUpMethod · 0.95
tearDownMethod · 0.95
finishMethod · 0.95
newSessionMethod · 0.95
UidTypeAlias · 0.92
UserIdMethod · 0.80
registerSessionMethod · 0.80
GetMethod · 0.65
EXPECTMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…