-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathtransport_test.go
59 lines (50 loc) · 889 Bytes
/
transport_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
package paxi
import (
"encoding/gob"
"testing"
)
func TestTransport(t *testing.T) {
// use message type A and B from codec_test.go
gob.Register(A{})
gob.Register(B{})
tests := []string{"tcp", "udp", "chan"}
for _, test := range tests {
server := NewTransport(test + "://127.0.0.1:1735")
server.Listen()
client := NewTransport(test + "://127.0.0.1:1735")
client.Dial()
client.Send(A{
I: 42,
S: "hello world",
B: true,
})
client.Send(B{
S: "hello gob",
})
m := server.Recv()
switch m.(type) {
case A:
t.Logf("recv message %+v", m)
default:
t.Error()
}
m = server.Recv()
switch m.(type) {
case B:
t.Logf("recv message %+v", m)
default:
t.Error()
}
client.Send(A{
I: 105,
S: "new world",
})
m = server.Recv()
switch m.(type) {
case A:
t.Logf("recv message %+v", m)
default:
t.Error()
}
}
}