-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
73 lines (71 loc) · 1.35 KB
/
client_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
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
package fastRPC
import (
"encoding/json"
"fmt"
"net"
"testing"
"time"
)
func TestClient(t *testing.T) {
dial, err := net.Dial("tcp", "localhost:8080")
if err != nil {
return
}
var data = DataStandards{
Header: nil,
Method: "HandlerHelloWorld",
Data: []byte("hello hello hello"),
}
marshal, err := json.Marshal(data)
if err != nil {
return
}
const times = 1000
for i := 0; i < times; i++ {
dial.Write(marshal)
var result = make([]byte, 1024)
_, err = dial.Read(result)
if err != nil {
return
}
ending := findBytesEnding(result)
var resp Response
err := json.Unmarshal(result[:ending], &resp)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(string(resp.Result))
time.Sleep(3 * time.Second)
}
}
func BenchmarkNewFastRPCServer(b *testing.B) {
dial, err := net.Dial("tcp", "localhost:8080")
if err != nil {
return
}
var data = DataStandards{
Header: nil,
Method: "HandlerHelloWorld",
Data: []byte("hello hello hello"),
}
marshal, err := json.Marshal(data)
if err != nil {
return
}
for i := 0; i < b.N; i++ {
dial.Write(marshal)
var result = make([]byte, 1024)
_, err = dial.Read(result)
if err != nil {
return
}
ending := findBytesEnding(result)
var resp Response
err := json.Unmarshal(result[:ending], &resp)
if err != nil {
fmt.Println(err.Error())
return
}
}
}