Skip to content

Commit

Permalink
add race test for Gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
mihasya committed Apr 6, 2018
1 parent 4cdad2c commit 9292013
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions gauge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package metrics

import (
"fmt"
"math/rand"
"sync"
"testing"
"time"
)

func BenchmarkGuage(b *testing.B) {
Expand All @@ -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))
Expand Down

0 comments on commit 9292013

Please sign in to comment.