diff --git a/gauge_test.go b/gauge_test.go index 1f2603d..d54d6f1 100644 --- a/gauge_test.go +++ b/gauge_test.go @@ -2,7 +2,10 @@ package metrics import ( "fmt" + "math/rand" + "sync" "testing" + "time" ) func BenchmarkGuage(b *testing.B) { @@ -13,6 +16,22 @@ func BenchmarkGuage(b *testing.B) { } } +// exercise race detector +func TestGaugeConcurrency(t *testing.T) { + rand.Seed(time.Now().Unix()) + g := NewGauge() + wg := &sync.WaitGroup{} + reps := 100 + for i := 0; i < reps; i++ { + wg.Add(1) + go func(g Gauge, wg *sync.WaitGroup) { + g.Update(rand.Int63()) + wg.Done() + }(g, wg) + } + wg.Wait() +} + func TestGauge(t *testing.T) { g := NewGauge() g.Update(int64(47))