Reduce peak client recalculation overhead
This commit is contained in:
parent
f49b679ce2
commit
5e760d52dd
2 changed files with 40 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package dnstt
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -59,3 +60,36 @@ func TestCollectorMatchesSubdomainsToRegisteredTunnel(t *testing.T) {
|
|||
t.Fatalf("active clients = %d, want 1", tunnel.ActiveClients)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollectorUpdatesPeakWhenActiveClientChangesGeoKey(t *testing.T) {
|
||||
now := time.Unix(1000, 0)
|
||||
firstResolver := netip.MustParseAddr("192.0.2.53")
|
||||
secondResolver := netip.MustParseAddr("198.51.100.53")
|
||||
c := NewCollector(
|
||||
[]string{"tunnel.example.com"},
|
||||
WithNow(func() time.Time { return now }),
|
||||
WithGeoResolver(fakeGeoResolver{
|
||||
labelNames: []string{"asn"},
|
||||
labels: map[netip.Addr]GeoLabels{
|
||||
firstResolver: {ASN: "64500"},
|
||||
secondResolver: {ASN: "64501"},
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
c.RecordQueryFrom("tunnel.example.com", "client-a", firstResolver, 120)
|
||||
c.RecordQueryFrom("tunnel.example.com", "client-a", secondResolver, 120)
|
||||
|
||||
foundChangedASN := false
|
||||
for _, series := range c.Snapshot().Tunnels["tunnel.example.com"].Series {
|
||||
if series.ASN == "64501" && series.PeakClients != 1 {
|
||||
t.Fatalf("peak clients for changed ASN = %d, want 1", series.PeakClients)
|
||||
}
|
||||
if series.ASN == "64501" {
|
||||
foundChangedASN = true
|
||||
}
|
||||
}
|
||||
if !foundChangedASN {
|
||||
t.Fatal("series for changed ASN not found")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue