-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmsg_whoami_test.go
128 lines (107 loc) · 2.83 KB
/
msg_whoami_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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package gofast
import "testing"
import "bytes"
import "time"
import "reflect"
func TestWaiEncode(t *testing.T) {
addr := <-testBindAddrs
lis, serverch := newServer("server", addr, "") // init server
transc := newClient("client", addr, "")
if err := transc.Handshake(); err != nil { // init client
t.Fatal(err)
}
transv := <-serverch
out := make([]byte, 1024)
ref := []byte{
6, 99, 108, 105, 101, 110, 116, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0,
}
wai := newWhoami(transc)
if out := wai.Encode(out); bytes.Compare(ref, out) != 0 {
t.Errorf("expected %v, got %v", ref, out)
}
time.Sleep(100 * time.Millisecond)
lis.Close()
transc.Close()
transv.Close()
}
func TestWaiDecode(t *testing.T) {
addr := <-testBindAddrs
lis, serverch := newServer("server", addr, "") // init server
transc := newClient("client", addr, "")
if err := transc.Handshake(); err != nil { // init client
t.Fatal(err)
}
transv := <-serverch
ver, out := testVersion(1), make([]byte, 1024)
wai, ref := &whoamiMsg{}, newWhoami(transc)
out = ref.Encode(out)
wai.version, wai.transport = &ver, transc
wai.Decode(out)
if !reflect.DeepEqual(ref, wai) {
t.Errorf("expected %#v, got %#v", ref, wai)
}
time.Sleep(100 * time.Millisecond)
lis.Close()
transc.Close()
transv.Close()
}
func TestWhoamiMisc(t *testing.T) {
addr := <-testBindAddrs
lis, serverch := newServer("server", addr, "") // init server
transc := newClient("client", addr, "")
if err := transc.Handshake(); err != nil { // init client
t.Fatal(err)
}
transv := <-serverch
wai := newWhoami(transc)
if wai.String() != "whoamiMsg" {
t.Errorf("expected whoamiMsg, got %v", wai.String())
}
if ref := "client,512"; ref != wai.Repr() {
t.Errorf("expected %v, got %v", ref, wai.Repr())
}
time.Sleep(100 * time.Millisecond)
lis.Close()
transc.Close()
transv.Close()
}
func BenchmarkWaiEncode(b *testing.B) {
addr := <-testBindAddrs
lis, serverch := newServer("server", addr, "") // init server
transc := newClient("client", addr, "")
if err := transc.Handshake(); err != nil { // init client
b.Fatal(err)
}
transv := <-serverch
out := make([]byte, 1024)
wai := newWhoami(transc)
for i := 0; i < b.N; i++ {
out = wai.Encode(out)
}
time.Sleep(100 * time.Millisecond)
lis.Close()
transc.Close()
transv.Close()
}
func BenchmarkWaiDecode(b *testing.B) {
addr := <-testBindAddrs
lis, serverch := newServer("server", addr, "") // init server
transc := newClient("client", addr, "")
if err := transc.Handshake(); err != nil { // init client
b.Fatal(err)
}
transv := <-serverch
ver, out := testVersion(1), make([]byte, 1024)
ref := newWhoami(transc)
ref.tags = "gzip"
out = ref.Encode(out)
wai := &whoamiMsg{}
wai.version, wai.transport = &ver, transc
for i := 0; i < b.N; i++ {
wai.Decode(out)
}
time.Sleep(100 * time.Millisecond)
lis.Close()
transc.Close()
transv.Close()
}