This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
router_client_test.go
80 lines (51 loc) · 1.96 KB
/
router_client_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
75
76
77
78
79
80
package gibson
import (
"time"
"github.com/apcera/nats"
"github.com/cloudfoundry/yagnats/fakeyagnats"
. "launchpad.net/gocheck"
)
type RCSuite struct{}
func init() {
Suite(&RCSuite{})
}
func (s *RCSuite) TestRouterClientRegistering(c *C) {
mbus := fakeyagnats.Connect()
routerClient := NewCFRouterClient("1.2.3.4", mbus)
routerClient.Register(123, "abc")
registrations := mbus.PublishedMessages("router.register")
c.Assert(len(registrations), Not(Equals), 0)
c.Assert(string(registrations[0].Data), Equals,
`{"uris":["abc"],"host":"1.2.3.4","port":123,"private_instance_id":"`+routerClient.PrivateInstanceId+`"}`)
}
func (s *RCSuite) TestRouterClientUnregistering(c *C) {
mbus := fakeyagnats.Connect()
routerClient := NewCFRouterClient("1.2.3.4", mbus)
routerClient.Unregister(123, "abc")
unregistrations := mbus.PublishedMessages("router.unregister")
c.Assert(len(unregistrations), Not(Equals), 0)
c.Assert(string(unregistrations[0].Data), Equals,
`{"uris":["abc"],"host":"1.2.3.4","port":123,"private_instance_id":"`+routerClient.PrivateInstanceId+`"}`)
}
func (s *RCSuite) TestRouterClientRouterStartHandling(c *C) {
mbus := fakeyagnats.Connect()
mbus.WhenSubscribing("router.start", func(handler nats.MsgHandler) error {
handler(&nats.Msg{
Data: []byte(`{"minimumRegisterIntervalInSeconds":1}`),
})
return nil
})
routerClient := NewCFRouterClient("1.2.3.4", mbus)
err := routerClient.Greet()
c.Assert(err, IsNil)
routerClient.Register(123, "abc")
c.Assert(len(mbus.PublishedMessages("router.register")), Equals, 1)
time.Sleep(600 * time.Millisecond)
c.Assert(len(mbus.PublishedMessages("router.register")), Equals, 1)
time.Sleep(600 * time.Millisecond)
c.Assert(len(mbus.PublishedMessages("router.register")), Equals, 2)
time.Sleep(600 * time.Millisecond)
c.Assert(len(mbus.PublishedMessages("router.register")), Equals, 2)
time.Sleep(600 * time.Millisecond)
c.Assert(len(mbus.PublishedMessages("router.register")), Equals, 3)
}