MCPcopy
hub / github.com/gotify/server / TestPing

Function TestPing

api/stream/stream_test.go:102–136  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

100}
101
102func TestPing(t *testing.T) {
103 mode.Set(mode.TestDev)
104
105 server, api := bootTestServer(staticUserID())
106 defer server.Close()
107 defer api.Close()
108
109 wsURL := wsURL(server.URL)
110
111 user := createClient(t, wsURL)
112 defer user.conn.Close()
113
114 ping := make(chan bool)
115 oldPingHandler := user.conn.PingHandler()
116 user.conn.SetPingHandler(func(appData string) error {
117 err := oldPingHandler(appData)
118 ping <- true
119 return err
120 })
121
122 startReading(user)
123
124 expectNoMessage(user)
125
126 select {
127 case <-time.After(2 * time.Second):
128 assert.Fail(t, "Expected ping but there was one :(")
129 case <-ping:
130 // expected
131 }
132
133 expectNoMessage(user)
134 api.Notify(1, &model.MessageExternal{Message: "HI"})
135 user.expectMessage(&model.MessageExternal{Message: "HI"})
136}
137
138func TestCloseClientOnNotReading(t *testing.T) {
139 mode.Set(mode.TestDev)

Callers

nothing calls this directly

Calls 10

SetFunction · 0.92
bootTestServerFunction · 0.85
staticUserIDFunction · 0.85
wsURLFunction · 0.85
startReadingFunction · 0.85
expectNoMessageFunction · 0.85
expectMessageMethod · 0.80
createClientFunction · 0.70
NotifyMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…