fix: harden websocket heartbeat under load
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestConfigureWSHeartbeat(t *testing.T) {
|
||||
originalPing, originalPong := pingPeriod, pongWait
|
||||
t.Cleanup(func() {
|
||||
pingPeriod, pongWait = originalPing, originalPong
|
||||
})
|
||||
|
||||
if err := configureWSHeartbeat(20, 120); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if pingPeriod != 20*time.Second || pongWait != 120*time.Second {
|
||||
t.Fatalf("heartbeat ping=%s pong=%s", pingPeriod, pongWait)
|
||||
}
|
||||
if err := configureWSHeartbeat(90, 90); err == nil {
|
||||
t.Fatal("expected invalid heartbeat configuration to fail")
|
||||
}
|
||||
if err := configureWSHeartbeat(0, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if pingPeriod != defaultWSPingPeriod || pongWait != defaultWSPongWait {
|
||||
t.Fatalf("default heartbeat ping=%s pong=%s", pingPeriod, pongWait)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user