Skip to content

Commit

Permalink
Merge pull request #568 from nats-io/update_client_pings
Browse files Browse the repository at this point in the history
Use client protocol updates
  • Loading branch information
kozlovic committed May 21, 2018
2 parents b075e03 + bee203e commit 7942a3c
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 239 deletions.
5 changes: 1 addition & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,6 @@ func (s *StanServer) processConnect(req *pb.ConnectRequest, replaceOld bool) err
ConnID: req.ConnID,
Protocol: req.Protocol,
PingInterval: req.PingInterval,
PingTimeout: req.PingTimeout,
PingMaxOut: req.PingMaxOut,
}
_, err := s.clients.register(info)
Expand Down Expand Up @@ -2737,10 +2736,8 @@ func (s *StanServer) finishConnectRequest(req *pb.ConnectRequest, replyInbox str
// In the future, we may want to return different values
// than the one the client sent in the connect request.
// For now, return the values from the request.
// Note1: Server and clients have possibly different HBs values.
// Note2: The following values will be 0s for older clients, which is fine.
// Note: Server and clients have possibly different HBs values.
cr.PingInterval = req.PingInterval
cr.PingTimeout = req.PingTimeout
cr.PingMaxOut = req.PingMaxOut
}
b, _ := cr.Marshal()
Expand Down
11 changes: 2 additions & 9 deletions server/server_clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ func testClientPings(t *testing.T, s *StanServer) {
ConnID: []byte(nuid.Next()),
Protocol: protocolOne,
PingInterval: int64(time.Second),
PingTimeout: int64(time.Second),
PingMaxOut: 3,
}
firstConnID := creq.ConnID
Expand All @@ -513,7 +512,7 @@ func testClientPings(t *testing.T, s *StanServer) {
if cresp.Error != "" {
t.Fatalf("Error on connect: %v", cresp.Error)
}
if cresp.Protocol != protocolOne || cresp.PingRequests == "" || cresp.PingInterval != int64(time.Second) || cresp.PingTimeout != int64(time.Second) || cresp.PingMaxOut != 3 {
if cresp.Protocol != protocolOne || cresp.PingRequests == "" || cresp.PingInterval != int64(time.Second) || cresp.PingMaxOut != 3 {
t.Fatalf("Unexpected response: %#v", cresp)
}

Expand Down Expand Up @@ -598,7 +597,6 @@ func testClientPings(t *testing.T, s *StanServer) {
ConnID: []byte(nuid.Next()),
Protocol: protocolOne,
PingInterval: int64(time.Second),
PingTimeout: int64(time.Second),
PingMaxOut: 3,
}
creqBytes, _ = creq.Marshal()
Expand Down Expand Up @@ -694,7 +692,6 @@ func TestPersistentStoreRecoverClientInfo(t *testing.T) {
ConnID: []byte(nuid.Next()),
Protocol: protocolOne,
PingInterval: int64(time.Second),
PingTimeout: int64(time.Second),
PingMaxOut: 3,
}
creqBytes, _ := creq.Marshal()
Expand All @@ -709,7 +706,7 @@ func TestPersistentStoreRecoverClientInfo(t *testing.T) {
if cresp.Error != "" {
t.Fatalf("Error on connect: %v", cresp.Error)
}
if cresp.Protocol != protocolOne || cresp.PingRequests == "" || cresp.PingInterval != int64(time.Second) || cresp.PingTimeout != int64(time.Second) || cresp.PingMaxOut != 3 {
if cresp.Protocol != protocolOne || cresp.PingRequests == "" || cresp.PingInterval != int64(time.Second) || cresp.PingMaxOut != 3 {
t.Fatalf("Unexpected response: %#v", cresp)
}

Expand All @@ -726,7 +723,6 @@ func TestPersistentStoreRecoverClientInfo(t *testing.T) {
proto := c.info.Protocol
cid := c.info.ConnID
pi := c.info.PingInterval
pt := c.info.PingTimeout
pmo := c.info.PingMaxOut
c.RUnlock()

Expand All @@ -739,9 +735,6 @@ func TestPersistentStoreRecoverClientInfo(t *testing.T) {
if pi != int64(time.Second) {
t.Fatalf("Recovered ping interval should be %v, got %v", time.Second, time.Duration(pi))
}
if pt != int64(time.Second) {
t.Fatalf("Recovered ping timeout should be %v, got %v", time.Second, time.Duration(pt))
}
if pmo != 3 {
t.Fatalf("Recovered ping max out should be 3, got %v", pmo)
}
Expand Down
Loading

0 comments on commit 7942a3c

Please sign in to comment.