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

Function TestDispatchSubscribe

server/session_test.go:222–269  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

220}
221
222func TestDispatchSubscribe(t *testing.T) {
223 uid := types.Uid(1)
224 s := test_makeSession(uid)
225 wg := sync.WaitGroup{}
226 r := responses{}
227 wg.Add(1)
228 go s.testWriteLoop(&r, &wg)
229
230 hub := &Hub{
231 join: make(chan *ClientComMessage, 10),
232 }
233 globals.hub = hub
234
235 defer func() {
236 globals.hub = nil
237 }()
238
239 msg := &ClientComMessage{
240 Sub: &MsgClientSub{
241 Id: "123",
242 Topic: "me",
243 Get: &MsgGetQuery{
244 What: "sub desc tags cred",
245 },
246 },
247 }
248
249 s.dispatch(msg)
250 close(s.send)
251 wg.Wait()
252
253 // Check we've routed the join request via the hub.
254 if len(r.messages) != 0 {
255 t.Errorf("responses: expected 0, received %d.", len(r.messages))
256 }
257 if len(hub.join) == 1 {
258 join := <-hub.join
259 if join.sess != s {
260 t.Error("Hub.join request: sess field expected to be the session under test.")
261 }
262 if join != msg {
263 t.Error("Hub.join request: subscribe message expected to be the original subscribe message.")
264 }
265 } else {
266 t.Errorf("Hub join messages: expected 1, received %d.", len(hub.join))
267 }
268 s.inflightReqs.Done()
269}
270
271func TestDispatchAlreadySubscribed(t *testing.T) {
272 uid := types.Uid(1)

Callers

nothing calls this directly

Calls 8

UidTypeAlias · 0.92
test_makeSessionFunction · 0.85
testWriteLoopMethod · 0.80
dispatchMethod · 0.80
WaitMethod · 0.80
ErrorMethod · 0.80
DoneMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…