1 Commits
Author SHA1 Message Date
sneak 83559c664c Parse the prefix on the prefix pages before looking it up (closes #71)
check / check (push) Canceled after 0s
Both prefix pages passed the URL text to the lookup as typed. A prefix
that does not parse made the lookup fail with an error that was not "no
route found", so the pages answered 500; a valid prefix written in any
form other than the one the tables store answered 404 although the
route exists. Both handlers now parse the prefix with net/netip, mask
it and look up the text form it prints, and answer 400 for a prefix
that does not parse.

Model: opus-5-5
2026-10-14 13:46:24 +00:00
2 changed files with 10 additions and 36 deletions

No files matched your search

+10 -15
View File
@@ -60,22 +60,17 @@ func New() *Tracker {
} }
} }
// SetConnected updates the connection status. Every connection after the // SetConnected updates the connection status
// first counts one reconnect.
func (t *Tracker) SetConnected(connected bool) { func (t *Tracker) SetConnected(connected bool) {
t.isConnected.Store(connected) wasConnected := t.isConnected.Swap(connected)
if !connected { if connected {
return t.mu.Lock()
} t.connectedSince = time.Now()
t.mu.Unlock()
t.mu.Lock() // Increment reconnect count (but not for the initial connection)
// connectedSince is zero until the first connection. if wasConnected || t.reconnectCount.Load() > 0 {
connectedBefore := !t.connectedSince.IsZero() t.reconnectCount.Add(1)
t.connectedSince = time.Now() }
t.mu.Unlock()
if connectedBefore {
t.reconnectCount.Add(1)
} }
} }
-21
View File
@@ -1,21 +0,0 @@
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)
}
}