-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy_test.go
More file actions
98 lines (84 loc) · 2.3 KB
/
proxy_test.go
File metadata and controls
98 lines (84 loc) · 2.3 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package proxy
import (
"context"
"io"
"io/ioutil"
"net"
"net/http"
"os"
"testing"
)
func TestClient(t *testing.T) {
c := NewHTTPClient("tcp", "localhost:7777", "tcp", "localhost:8081")
rep, err := c.Get("http://localhost:8081/swagger")
if err != nil {
t.Fatal("Could not Get ", err)
}
t.Log("Status ", rep.Status)
//rep.Write(os.Stdout)
}
func TestWriteHeader(t *testing.T) {
ErrorHTTP(200, "testService", "OK good", os.Stdout)
}
func executeNHTTPRequest(b *testing.B, c http.Client, req *http.Request) {
for i := 0; i < b.N; i++ {
rep, err := c.Do(req)
if err != nil {
b.Fatal("Could not Get ", err)
}
io.Copy(ioutil.Discard, rep.Body)
rep.Body.Close()
}
}
//To run benchmark test launch:
//
//go test -bench ^BenchmarkTest -benchtime 30000x
func BenchmarkTestDirectHTTP(b *testing.B) {
c := http.Client{}
req, _ := http.NewRequest("GET", "http://localhost:5566/test", nil)
executeNHTTPRequest(b, c, req)
}
func BenchmarkTestHttpd(b *testing.B) {
c := http.Client{}
req, _ := http.NewRequest("GET", "http://localhost/test", nil)
executeNHTTPRequest(b, c, req)
}
func BenchmarkTestDirectUNIX(b *testing.B) {
c := http.Client{
Transport: &http.Transport{
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
return net.Dial("unix", "/tmp/testhttp.sock")
},
},
}
req, _ := http.NewRequest("GET", "http://unix/test", nil)
executeNHTTPRequest(b, c, req)
}
func BenchmarkTestProxyTcpTcp(b *testing.B) {
c := NewHTTPClient("tcp", "localhost:7777", "tcp", "localhost:5566")
req, _ := http.NewRequest("GET", "http://localhost:5566/test", nil)
executeNHTTPRequest(b, c, req)
}
func BenchMarkTestProxyWithRegistry(b *testing.B) {
}
func BenchmarkTestProxyTcpUnix(b *testing.B) {
c := NewHTTPClient("tcp", "localhost:7777", "unix", "/tmp/testhttp.sock")
req, _ := http.NewRequest("GET", "http://localhost:5566/test", nil)
executeNHTTPRequest(b, c, req)
}
//go test -run=^$ -bench BenchmarkTemplateParallel -v -benchtime=20s
func BenchmarkTemplateParallel(b *testing.B) {
c := http.Client{}
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
resp, err := c.Get("http://localhost:8080/proxy/httptest")
if err != nil {
b.Fatal(err)
}
if resp.StatusCode != 200 {
b.Log("Fail ", resp.Status)
}
io.Copy(ioutil.Discard, resp.Body)
}
})
}