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

Function TestRegisterSessionCreateSubFailed

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

Source from the content-addressed store, hash-verified

1787}
1788
1789func TestRegisterSessionCreateSubFailed(t *testing.T) {
1790 topicName := "grpTest"
1791 numUsers := 1
1792 helper := TopicTestHelper{}
1793 helper.setUp(t, numUsers, types.TopicCatGrp, topicName, false)
1794 defer helper.tearDown()
1795 if len(helper.topic.sessions) != 0 {
1796 helper.finish()
1797 t.Fatalf("Initially attached sessions: expected 0 vs found %d", len(helper.topic.sessions))
1798 }
1799
1800 // New uid. This should attempt to add a new subscription
1801 // which produces an error b/c authLevel isn't root.
1802 uid := types.Uid(10001)
1803 s, r := helper.newSession("test-sid", uid)
1804 helper.sessions = append(helper.sessions, s)
1805 helper.results = append(helper.results, r)
1806
1807 join := &ClientComMessage{
1808 Original: topicName,
1809 Sub: &MsgClientSub{
1810 Id: "id456",
1811 Topic: topicName,
1812 },
1813 AsUser: uid.UserId(),
1814 AuthLvl: int(auth.LevelAuth),
1815 sess: s,
1816 }
1817
1818 helper.ss.EXPECT().Get(topicName, uid, true).Return(nil, types.ErrInternal)
1819
1820 helper.topic.registerSession(join)
1821 helper.finish()
1822
1823 // Check for errors from testHubLoop
1824 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
1825 t.Fatal(errorMsgs[0].Ctrl.Text)
1826 }
1827
1828 if len(s.subs) != 0 {
1829 t.Errorf("Session subscriptions: expected 0, found %d", len(s.subs))
1830 }
1831 online := helper.topic.perUser[uid].online
1832 if online != 0 {
1833 t.Errorf("Number of online sessions: expected 0, found %d", online)
1834 }
1835 // Session output.
1836 registerSessionVerifyOutputs(t, r, []int{http.StatusInternalServerError})
1837 // Presence notifications.
1838 if len(helper.hubMessages) != 0 {
1839 t.Errorf("Hub isn't expected to receive any messages, received %d", len(helper.hubMessages))
1840 }
1841}
1842
1843func TestRegisterSessionAsChanUserNotChanSubcriber(t *testing.T) {
1844 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…