-
Notifications
You must be signed in to change notification settings - Fork 76
/
socket_test.go
53 lines (45 loc) · 913 Bytes
/
socket_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
package paxi
import (
"encoding/gob"
"testing"
)
var id1 = ID("1.1")
var id2 = ID("1.2")
var Address = map[ID]string{
id1: "127.0.0.1:1736",
id2: "127.0.0.1:1737",
}
type MSG struct {
I int
S string
}
func run(transport string, t *testing.T) {
gob.Register(MSG{})
var send interface{}
var recv interface{}
address := make(map[ID]string)
if transport != "" {
address[id1] = transport + "://" + Address[id1]
address[id2] = transport + "://" + Address[id2]
} else {
address[id1] = Address[id1]
address[id2] = Address[id2]
}
send = MSG{42, "hello"}
go func() {
sock1 := NewSocket(id1, address)
defer sock1.Close()
sock1.Broadcast(send)
}()
sock2 := NewSocket(id2, address)
defer sock2.Close()
recv = sock2.Recv()
if send.(MSG) != recv.(MSG) {
t.Error("expect recv equal to send message")
}
}
func TestSocket(t *testing.T) {
run("chan", t)
run("tcp", t)
run("udp", t)
}