github.com/ava-labs/subnet-evm@v0.6.4/metrics/gauge_test.go (about)

     1  package metrics
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func BenchmarkGauge(b *testing.B) {
     8  	g := NewGauge()
     9  	b.ResetTimer()
    10  	for i := 0; i < b.N; i++ {
    11  		g.Update(int64(i))
    12  	}
    13  }
    14  
    15  func TestGaugeSnapshot(t *testing.T) {
    16  	g := NewGauge()
    17  	g.Update(int64(47))
    18  	snapshot := g.Snapshot()
    19  	g.Update(int64(0))
    20  	if v := snapshot.Value(); v != 47 {
    21  		t.Errorf("g.Value(): 47 != %v\n", v)
    22  	}
    23  }
    24  
    25  func TestGetOrRegisterGauge(t *testing.T) {
    26  	r := NewRegistry()
    27  	NewRegisteredGauge("foo", r).Update(47)
    28  	if g := GetOrRegisterGauge("foo", r); g.Snapshot().Value() != 47 {
    29  		t.Fatal(g)
    30  	}
    31  }