MCPcopy
hub / github.com/valyala/fasthttp / TestServerTimeoutErrorWithCode

Function TestServerTimeoutErrorWithCode

server_test.go:3717–3749  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3715}
3716
3717func TestServerTimeoutErrorWithCode(t *testing.T) {
3718 t.Parallel()
3719
3720 s := &Server{
3721 Handler: func(ctx *RequestCtx) {
3722 go func() {
3723 ctx.Success("aaa/bbb", []byte("xxxyyy"))
3724 }()
3725 ctx.TimeoutErrorWithCode("should be ignored", 234)
3726 ctx.TimeoutErrorWithCode("stolen ctx", StatusBadRequest)
3727 },
3728 }
3729
3730 rw := &readWriter{}
3731 rw.r.WriteString("GET /foo HTTP/1.1\r\nHost: google.com\r\n\r\n")
3732 rw.r.WriteString("GET /foo HTTP/1.1\r\nHost: google.com\r\n\r\n")
3733
3734 if err := s.ServeConn(rw); err != nil {
3735 t.Fatalf("Unexpected error from serveConn: %v", err)
3736 }
3737
3738 br := bufio.NewReader(&rw.w)
3739 verifyResponse(t, br, StatusBadRequest, string(defaultContentType), "stolen ctx")
3740 verifyResponse(t, br, StatusBadRequest, string(defaultContentType), "stolen ctx")
3741
3742 data, err := io.ReadAll(br)
3743 if err != nil {
3744 t.Fatalf("Unexpected error when reading remaining data: %v", err)
3745 }
3746 if len(data) != 0 {
3747 t.Fatalf("Unexpected data read after the first response %q. Expecting %q", data, "")
3748 }
3749}
3750
3751func TestServerTimeoutError(t *testing.T) {
3752 t.Parallel()

Callers

nothing calls this directly

Calls 6

ServeConnMethod · 0.95
verifyResponseFunction · 0.85
SuccessMethod · 0.80
TimeoutErrorWithCodeMethod · 0.80
NewReaderMethod · 0.80
WriteStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…