mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-06 04:42:42 +00:00
wgengine: instrument with usermetrics
Updates tailscale/corp#22075 Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
committed by
Kristoffer Dalby
parent
adc8368964
commit
40c991f6b8
@@ -4,8 +4,11 @@
|
||||
package clientmetric
|
||||
|
||||
import (
|
||||
"expvar"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
)
|
||||
|
||||
func TestDeltaEncBuf(t *testing.T) {
|
||||
@@ -107,3 +110,49 @@ func TestWithFunc(t *testing.T) {
|
||||
t.Errorf("second = %q; want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAggregateCounter(t *testing.T) {
|
||||
clearMetrics()
|
||||
|
||||
c := qt.New(t)
|
||||
|
||||
expv1 := &expvar.Int{}
|
||||
expv2 := &expvar.Int{}
|
||||
expv3 := &expvar.Int{}
|
||||
|
||||
aggCounter := NewAggregateCounter("agg_counter")
|
||||
|
||||
aggCounter.Register(expv1)
|
||||
c.Assert(aggCounter.Value(), qt.Equals, int64(0))
|
||||
|
||||
expv1.Add(1)
|
||||
c.Assert(aggCounter.Value(), qt.Equals, int64(1))
|
||||
|
||||
aggCounter.Register(expv2)
|
||||
c.Assert(aggCounter.Value(), qt.Equals, int64(1))
|
||||
|
||||
expv1.Add(1)
|
||||
expv2.Add(1)
|
||||
c.Assert(aggCounter.Value(), qt.Equals, int64(3))
|
||||
|
||||
// Adding a new expvar should not change the value
|
||||
// and any value the counter already had is reset
|
||||
expv3.Set(5)
|
||||
aggCounter.Register(expv3)
|
||||
c.Assert(aggCounter.Value(), qt.Equals, int64(3))
|
||||
|
||||
// Registering the same expvar multiple times should not change the value
|
||||
aggCounter.Register(expv3)
|
||||
c.Assert(aggCounter.Value(), qt.Equals, int64(3))
|
||||
|
||||
aggCounter.UnregisterAll()
|
||||
c.Assert(aggCounter.Value(), qt.Equals, int64(0))
|
||||
|
||||
// Start over
|
||||
expv3.Set(5)
|
||||
aggCounter.Register(expv3)
|
||||
c.Assert(aggCounter.Value(), qt.Equals, int64(0))
|
||||
|
||||
expv3.Set(5)
|
||||
c.Assert(aggCounter.Value(), qt.Equals, int64(5))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user