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

Function TestWriteMessageFails

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

Source from the content-addressed store, hash-verified

37}
38
39func TestWriteMessageFails(t *testing.T) {
40 mode.Set(mode.TestDev)
41 oldWrite := writeJSON
42 // try emulate an write error, mostly this should kill the ReadMessage goroutine first but you'll never know.
43 writeJSON = func(conn *websocket.Conn, v interface{}) error {
44 return errors.New("asd")
45 }
46 defer func() {
47 writeJSON = oldWrite
48 }()
49 defer leaktest.Check(t)()
50
51 server, api := bootTestServer(func(context *gin.Context) {
52 auth.RegisterAuthentication(context, nil, 1, "")
53 })
54 defer server.Close()
55 defer api.Close()
56
57 wsURL := wsURL(server.URL)
58 user := testClient(t, wsURL)
59
60 waitForConnectedClients(api, 1)
61
62 clients := clients(api, 1)
63 assert.NotEmpty(t, clients)
64
65 api.Notify(1, &model.MessageExternal{Message: "HI"})
66 user.expectNoMessage()
67}
68
69func TestWritePingFails(t *testing.T) {
70 mode.Set(mode.TestDev)

Callers

nothing calls this directly

Calls 10

SetFunction · 0.92
RegisterAuthenticationFunction · 0.92
bootTestServerFunction · 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…