Let bgp_peer_count drop to 0 (closes #92) #93

Merged
clawbot merged 1 commits from issue-92-peer-count-zero into next 2026-10-19 12:41:16 +02:00
2 changed files with 16 additions and 1 deletions
Showing only changes of commit 714e7f6f4e - Show all commits
+1 -1
View File
@@ -168,7 +168,7 @@ func (t *Tracker) RecordWithdrawal() {
// SetBGPPeerCount updates the current BGP peer count // SetBGPPeerCount updates the current BGP peer count
func (t *Tracker) SetBGPPeerCount(count int) { func (t *Tracker) SetBGPPeerCount(count int) {
// BGP peer count is always small (< 1000), so int32 is safe // BGP peer count is always small (< 1000), so int32 is safe
if count > 0 && count < 1<<31 { if count >= 0 && count < 1<<31 {
t.bgpPeerCount.Store(int32(count)) t.bgpPeerCount.Store(int32(count))
} }
} }
+15
View File
@@ -25,3 +25,18 @@ func TestReconnectCount(t *testing.T) {
t.Fatalf("reconnect count = %d, want %d", got, wantReconnects) t.Fatalf("reconnect count = %d, want %d", got, wantReconnects)
} }
} }
// TestBGPPeerCountDropsToZero sets a peer count of 1 and then 0, the way the
// streamer does when the last peer's session ends, and expects 0 back.
func TestBGPPeerCountDropsToZero(t *testing.T) {
t.Parallel()
tracker := metrics.New()
tracker.SetBGPPeerCount(1)
tracker.SetBGPPeerCount(0)
if got := tracker.GetBGPPeerCount(); got != 0 {
t.Fatalf("peer count = %d after setting 0, want 0", got)
}
}