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

Function TestWritePingFails

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

Source from the content-addressed store, hash-verified

67}
68
69func TestWritePingFails(t *testing.T) {
70 mode.Set(mode.TestDev)
71 oldPing := ping
72 // try emulate an write error, mostly this should kill the ReadMessage gorouting first but you'll never know.
73 ping = func(conn *websocket.Conn) error {
74 return errors.New("asd")
75 }
76 defer func() {
77 ping = oldPing
78 }()
79
80 defer leaktest.CheckTimeout(t, 10*time.Second)()
81
82 server, api := bootTestServer(staticUserID())
83 defer api.Close()
84 defer server.Close()
85
86 wsURL := wsURL(server.URL)
87 user := testClient(t, wsURL)
88 defer user.conn.Close()
89
90 waitForConnectedClients(api, 1)
91
92 clients := clients(api, 1)
93
94 assert.NotEmpty(t, clients)
95
96 time.Sleep(api.pingPeriod + (50 * time.Millisecond)) // waiting for ping
97
98 api.Notify(1, &model.MessageExternal{Message: "HI"})
99 user.expectNoMessage()
100}
101
102func TestPing(t *testing.T) {
103 mode.Set(mode.TestDev)

Callers

nothing calls this directly

Calls 10

SetFunction · 0.92
bootTestServerFunction · 0.85
staticUserIDFunction · 0.85
wsURLFunction · 0.85
testClientFunction · 0.85
waitForConnectedClientsFunction · 0.85
clientsFunction · 0.85
expectNoMessageMethod · 0.80
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…