Fixed handling of unprompted PONG protocols

- The number of outstanding PINGs is now reset whenever the server
receives a PONG from the client.
- Updated parser test to check c.pout.
- Added a test to check for unprompted PONGs.

Resolves issue: https://github.com/nats-io/gnatsd/issues/168
This commit is contained in:
Ivan Kozlovic
2016-03-23 14:26:06 -07:00
parent 3dd490a449
commit 76324844a9
3 changed files with 59 additions and 4 deletions

View File

@@ -93,10 +93,16 @@ func TestParsePong(t *testing.T) {
if err != nil || c.state != OP_START {
t.Fatalf("Unexpected: %d : %v\n", c.state, err)
}
if c.pout != 0 {
t.Fatalf("Unexpected pout value: %d vs 0\n", c.pout)
}
err = c.parse(pong)
if err != nil || c.state != OP_START {
t.Fatalf("Unexpected: %d : %v\n", c.state, err)
}
if c.pout != 0 {
t.Fatalf("Unexpected pout value: %d vs 0\n", c.pout)
}
// Should tolerate spaces
pong = []byte("PONG \r")
err = c.parse(pong)
@@ -109,8 +115,11 @@ func TestParsePong(t *testing.T) {
if err != nil || c.state != OP_START {
t.Fatalf("Unexpected: %d : %v\n", c.state, err)
}
if c.pout != 0 {
t.Fatalf("Unexpected pout value: %d vs 0\n", c.pout)
}
// Should be adjusting c.pout, Pings Outstanding
// Should be adjusting c.pout (Pings Outstanding): reset to 0
c.state = OP_START
c.pout = 10
pong = []byte("PONG\r\n")
@@ -118,8 +127,8 @@ func TestParsePong(t *testing.T) {
if err != nil || c.state != OP_START {
t.Fatalf("Unexpected: %d : %v\n", c.state, err)
}
if c.pout != 9 {
t.Fatalf("Unexpected pout: %d vs %d\n", c.pout, 9)
if c.pout != 0 {
t.Fatalf("Unexpected pout: %d vs 0\n", c.pout)
}
}