check / check (push) Canceled after 0s
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
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)
|
|
}
|
|
}
|