-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbenchmark_test.go
More file actions
42 lines (39 loc) · 832 Bytes
/
Copy pathbenchmark_test.go
File metadata and controls
42 lines (39 loc) · 832 Bytes
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
package main
import (
"io"
"net/http"
"net/http/httputil"
"testing"
"time"
)
func TestMain(m *testing.M) {
// create a http server
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
io.WriteString(writer, "work well!")
})
go http.ListenAndServe(":15342", nil)
time.Sleep(time.Second)
m.Run()
}
func TestBenchmark_Run(t *testing.T) {
// create a request
r, err := http.NewRequest("GET", "http://127.0.0.0.1:15342", nil)
if err != nil {
t.Fatal(err)
}
writeBytes, err := httputil.DumpRequest(r, true)
if err != nil {
t.Fatal(err)
}
p := &benchmark{
connectionNum: 100,
reqNum: 20000,
requestBytes: writeBytes,
target: "127.0.0.1:15342",
schema: r.URL.Scheme,
timeout: 30000,
reqConnList: make([]*ReqConn, 0),
}
p.Run()
p.Print()
}