-
Notifications
You must be signed in to change notification settings - Fork 57
/
e2e_bench_test.go
44 lines (39 loc) · 968 Bytes
/
e2e_bench_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
package typhon
import (
"context"
"net"
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func BenchmarkRequestResponse(b *testing.B) {
b.ReportAllocs()
svc := Service(func(req Request) Response {
rsp := req.Response(nil)
rsp.Header.Set("a", "b")
rsp.Header.Set("b", "b")
rsp.Header.Set("c", "b")
return rsp
})
addr := &net.UnixAddr{
Net: "unix",
Name: "/tmp/typhon-test.sock"}
l, _ := net.ListenUnix("unix", addr)
defer l.Close()
s, _ := Serve(svc, l)
defer s.Stop(context.Background())
conn, err := net.DialUnix("unix", nil, addr)
require.NoError(b, err)
defer conn.Close()
sockTransport := &http.Transport{
DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
return conn, nil
}}
ctx := context.Background()
req := NewRequest(ctx, "GET", "http://localhost/foo", nil)
sockSvc := HttpService(sockTransport)
b.ResetTimer()
for i := 0; i < b.N; i++ {
req.SendVia(sockSvc).Response()
}
}