forked from valyala/fasthttp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_race_test.go
46 lines (38 loc) · 896 Bytes
/
server_race_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//go:build race
package fasthttp
import (
"context"
"github.com/valyala/fasthttp/fasthttputil"
"math"
"testing"
)
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(context.Background())
cancelFunc()
s.ShutdownWithContext(ctx)
}