MCPcopy
hub / github.com/gofiber/fiber / Test_SSE_NewWritesHeartbeat

Function Test_SSE_NewWritesHeartbeat

middleware/sse/sse_test.go:261–282  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

259}
260
261func Test_SSE_NewWritesHeartbeat(t *testing.T) {
262 t.Parallel()
263
264 app := fiber.New()
265 app.Get("/events", New(Config{
266 HeartbeatInterval: 5 * time.Millisecond,
267 Handler: func(_ fiber.Ctx, stream *Stream) error {
268 select {
269 case <-time.After(150 * time.Millisecond):
270 return nil
271 case <-stream.Done():
272 return stream.Err()
273 }
274 },
275 }))
276
277 resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/events", http.NoBody))
278 require.NoError(t, err)
279 body, err := io.ReadAll(resp.Body)
280 require.NoError(t, err)
281 require.Contains(t, string(body), ":\n\n")
282}
283
284func Test_SSE_OnCloseReceivesNilAfterNormalClose(t *testing.T) {
285 t.Parallel()

Callers

nothing calls this directly

Calls 7

TestMethod · 0.80
ContainsMethod · 0.80
NewFunction · 0.70
NewMethod · 0.65
GetMethod · 0.65
DoneMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected