mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user