reject sub-10ns ping intervals and clamp pinger jitter

This commit is contained in:
Jay
2026-08-11 16:09:54 -04:00
parent 54ac311051
commit 296872faee
3 changed files with 42 additions and 3 deletions
+31
View File
@@ -322,6 +322,37 @@ func TestConnection_Heartbeat(t *testing.T) {
})
}
func TestStartPingerSubMinimumInterval(t *testing.T) {
// Construct directly to bypass NewConnectionConfig validation; the
// jitter clamp alone must prevent the Int63n(0) panic.
conn := &Connection{
socket: honeybeetest.NewMockSocket(),
config: ConnectionConfig{PingInterval: 5 * time.Nanosecond},
incoming: make(chan []byte, 1),
errors: make(chan error, 1),
done: make(chan struct{}),
}
finished := make(chan struct{})
go func() {
defer close(finished)
conn.startPinger()
}()
// let several jittered intervals elapse
time.Sleep(50 * time.Millisecond)
conn.Close()
honeybeetest.Eventually(t, func() bool {
select {
case <-finished:
return true
default:
return false
}
}, "pinger should exit cleanly after Close")
}
// ----------------------------------------------------------------------------
// Send
// ----------------------------------------------------------------------------