-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathlookup_test.go
65 lines (52 loc) · 1.15 KB
/
lookup_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
package nsq
import (
"testing"
"time"
)
var (
nsqlookup = []string{
"localhost:4161", // nsqlookup-1
"localhost:4163", // nsqlookup-2
"localhost:4165", // nsqlookup-3
}
nsqd = []string{
"localhost:4151", // nsqd-1
"localhost:4153", // nsqd-2
"localhost:4155", // nsqd-3
}
)
func TestLookup(t *testing.T) {
for _, node := range nsqd {
c := &Client{Address: node}
if err := c.CreateTopic("test-lookup"); err != nil {
t.Error(err)
return
}
// stack cleanup callbacks
defer func() {
if err := c.DeleteTopic("test-lookup"); err != nil {
t.Error(err)
}
}()
}
// Allow some time for the nsqd nodes to inform nsqlookupd that they host
// a specific topic.
time.Sleep(100 * time.Millisecond)
res, err := (&LookupClient{Addresses: nsqlookup}).Lookup("test-lookup")
if err != nil {
t.Error(err)
return
}
if len(res.Channels) != 0 {
t.Error("too many channels were reported by the lookup operation")
for _, c := range res.Channels {
t.Log(c)
}
}
if len(res.Producers) != 3 {
t.Error("not enough producers reported by the lookup operation")
for _, p := range res.Producers {
t.Logf("%#v", p)
}
}
}