check / check (push) Waiting to run
`reconnect_count` in `/api/v1/stats` stayed 0 however often the stream reconnected: `SetConnected` counted a reconnect only while the stream was still marked connected, and the streamer always marks it disconnected first. It now counts one reconnect for every connection after the first, recognised by the zero `connectedSince` before the first connection. A test connects and disconnects twice and expects 2. Model: opus-5-5
22 lines
574 B
Go
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)
|
|
}
|
|
}
|