mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-13 15:46:49 +03:00
4d25421ae5
The Go team doesn't support this version anymore. This is required to update our golang.org/x/... dependencies.
48 lines
888 B
Go
48 lines
888 B
Go
//go:build race
|
|
|
|
package fasthttp
|
|
|
|
import (
|
|
"context"
|
|
"math"
|
|
"testing"
|
|
|
|
"github.com/valyala/fasthttp/fasthttputil"
|
|
)
|
|
|
|
func TestServerDoneRace(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
s := &Server{
|
|
Handler: func(ctx *RequestCtx) {
|
|
for i := 0; i < math.MaxInt; i++ {
|
|
ctx.Done()
|
|
}
|
|
},
|
|
}
|
|
|
|
ln := fasthttputil.NewInmemoryListener()
|
|
defer ln.Close()
|
|
|
|
go func() {
|
|
if err := s.Serve(ln); err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
}()
|
|
|
|
c, err := ln.Dial()
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
defer c.Close()
|
|
if _, err = c.Write([]byte("POST / HTTP/1.1\r\nHost: go.dev\r\nContent-Length: 3\r\n\r\nABC" +
|
|
"\r\n\r\n" + // <-- this stuff is bogus, but we'll ignore it
|
|
"GET / HTTP/1.1\r\nHost: go.dev\r\n\r\n")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ctx, cancelFunc := context.WithCancel(t.Context())
|
|
cancelFunc()
|
|
|
|
s.ShutdownWithContext(ctx)
|
|
}
|