-
Notifications
You must be signed in to change notification settings - Fork 164
/
zmq41_test.go
74 lines (61 loc) · 1.38 KB
/
zmq41_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
package zmq4_test
import (
zmq "github.com/pebbe/zmq4"
"testing"
)
func TestRemoteEndpoint(t *testing.T) {
if _, minor, _ := zmq.Version(); minor < 1 {
t.Skip("RemoteEndpoint not avalable in ZeroMQ versions prior to 4.1.0")
}
addr := "tcp://127.0.0.1:9560"
peer := "127.0.0.1"
var rep, req *zmq.Socket
defer func() {
for _, s := range []*zmq.Socket{rep, req} {
if s != nil {
s.SetLinger(0)
s.Close()
}
}
}()
rep, err := zmq.NewSocket(zmq.REP)
if err != nil {
t.Fatal("NewSocket:", err)
}
req, err = zmq.NewSocket(zmq.REQ)
if err != nil {
t.Fatal("NewSocket:", err)
}
if err = rep.Bind(addr); err != nil {
t.Fatal("rep.Bind:", err)
}
if err = req.Connect(addr); err != nil {
t.Fatal("req.Connect:", err)
}
tmp := "test"
if _, err = req.Send(tmp, 0); err != nil {
t.Fatal("req.Send:", err)
}
// get message with peer address (remote endpoint)
msg, props, err := rep.RecvWithMetadata(0, "Peer-Address")
if err != nil {
t.Fatal("rep.RecvWithMetadata:", err)
return
}
if msg != tmp {
t.Errorf("rep.RecvWithMetadata: expected %q, got %q", tmp, msg)
}
if p := props["Peer-Address"]; p != peer {
t.Errorf("rep.RecvWithMetadata: expected Peer-Address == %q, got %q", peer, p)
}
err = rep.Close()
rep = nil
if err != nil {
t.Fatal("rep.Close:", err)
}
err = req.Close()
req = nil
if err != nil {
t.Fatal("req.Close:", err)
}
}