github.com/anycable/anycable-go@v1.5.1/metrics/gauge_test.go (about) 1 package metrics 2 3 import ( 4 "sync" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestGauge(t *testing.T) { 11 g := NewGauge("test", "") 12 assert.Equal(t, uint64(0), g.Value()) 13 g.Set(20) 14 assert.Equal(t, uint64(20), g.Value()) 15 } 16 17 func TestGaugeIncDec(t *testing.T) { 18 g := NewGauge("test", "") 19 20 var wg sync.WaitGroup 21 22 for i := 0; i < 20; i++ { 23 wg.Add(1) 24 25 go func() { 26 g.Inc() 27 wg.Done() 28 }() 29 } 30 31 for i := 0; i < 13; i++ { 32 wg.Add(1) 33 34 go func() { 35 g.Dec() 36 wg.Done() 37 }() 38 } 39 40 wg.Wait() 41 42 assert.Equal(t, uint64(7), g.Value()) 43 }