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

Function Test_App_ReadTimeout

app_test.go:2666–2706  ·  view source on GitHub ↗

go test -run Test_App_ReadTimeout

(t *testing.T)

Source from the content-addressed store, hash-verified

2664
2665// go test -run Test_App_ReadTimeout
2666func Test_App_ReadTimeout(t *testing.T) {
2667 t.Parallel()
2668 app := New(Config{
2669 ReadTimeout: time.Nanosecond,
2670 IdleTimeout: time.Minute,
2671 DisableKeepalive: true,
2672 })
2673
2674 ln, err := net.Listen(NetworkTCP4, "127.0.0.1:0")
2675 require.NoError(t, err)
2676 addr := ln.Addr().String()
2677
2678 app.Get("/read-timeout", func(c Ctx) error {
2679 return c.SendString("I should not be sent")
2680 })
2681
2682 go func() {
2683 time.Sleep(500 * time.Millisecond)
2684
2685 conn, err := net.Dial(NetworkTCP4, addr)
2686 assert.NoError(t, err)
2687 defer func(conn net.Conn) {
2688 closeErr := conn.Close()
2689 assert.NoError(t, closeErr)
2690 }(conn)
2691
2692 _, err = conn.Write([]byte("HEAD /read-timeout HTTP/1.1\r\n"))
2693 assert.NoError(t, err)
2694
2695 buf := make([]byte, 1024)
2696 var n int
2697 n, err = conn.Read(buf)
2698
2699 assert.NoError(t, err)
2700 assert.True(t, bytes.Contains(buf[:n], []byte("408 Request Timeout")))
2701
2702 assert.NoError(t, app.Shutdown())
2703 }()
2704
2705 require.NoError(t, app.Listener(ln, ListenConfig{DisableStartupMessage: true}))
2706}
2707
2708// go test -run Test_App_BadRequest
2709func Test_App_BadRequest(t *testing.T) {

Callers

nothing calls this directly

Calls 12

ListenMethod · 0.80
AddrMethod · 0.80
ContainsMethod · 0.80
ShutdownMethod · 0.80
ListenerMethod · 0.80
NewFunction · 0.70
StringMethod · 0.65
GetMethod · 0.65
SendStringMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.65
ReadMethod · 0.45

Tested by

no test coverage detected