-
Notifications
You must be signed in to change notification settings - Fork 95
/
monitor_test.go
63 lines (45 loc) · 1.22 KB
/
monitor_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
package goczmq
import (
"fmt"
"testing"
)
func assertEvent(t *testing.T, monitor *Monitor, expectedEvent string) {
poller, _ := NewPoller(monitor.Socket())
defer poller.Destroy()
socket, _ := poller.Wait(100)
if socket == nil {
t.Error("No messages received on monitor socket for 1 second")
return
}
msg, _ := socket.RecvMessage()
if len(msg) != 3 {
t.Errorf("Expected message with 3 frames, got %v", len(msg))
}
eventName := string(msg[0])
if eventName != expectedEvent {
t.Errorf("Expected %v event, got %v", expectedEvent, eventName)
return
}
}
func TestMonitor(t *testing.T) {
client := NewSock(Dealer)
defer client.Destroy()
clientmon := NewMonitor(client)
defer clientmon.Destroy()
clientmon.Verbose()
clientmon.Listen("LISTENING")
clientmon.Listen("ACCEPTED")
clientmon.Start()
server := NewSock(Dealer)
defer server.Destroy()
servermon := NewMonitor(server)
defer servermon.Destroy()
servermon.Listen("CONNECTED")
servermon.Listen("DISCONNECTED")
servermon.Start()
port, _ := client.Bind("tcp://127.0.0.1:*")
assertEvent(t, clientmon, "LISTENING")
server.Connect(fmt.Sprint("tcp://127.0.0.1:", port))
assertEvent(t, servermon, "CONNECTED")
assertEvent(t, clientmon, "ACCEPTED")
}