Files
routewatch/internal/metrics/metrics_test.go
T
sneak d9c040c864
check / check (push) Canceled after 0s
Count every reconnect in reconnect_count (closes #68)
SetConnected counted a reconnect only if the stream was still marked
connected or the count was already above zero. The streamer always marks
the stream disconnected before connecting again, so the count stayed 0.
It now counts one reconnect for every connection after the first, using
the time of the previous connection, which is zero until the first one.

Model: opus-5-5
2026-10-14 13:02:54 +00:00

22 lines
574 B
Go

package metrics
import "testing"
// TestReconnectCount connects three times with a disconnect between each, the
// way the streamer does, and expects every connection after the first to count
// one reconnect.
func TestReconnectCount(t *testing.T) {
tracker := New()
tracker.SetConnected(true)
tracker.SetConnected(false)
tracker.SetConnected(true)
tracker.SetConnected(false)
tracker.SetConnected(true)
const wantReconnects = 2
if got := tracker.GetReconnectCount(); got != wantReconnects {
t.Fatalf("reconnect count = %d, want %d", got, wantReconnects)
}
}