From 4cdad2ce7c6cc23933068f22b934ea4e4cb02a73 Mon Sep 17 00:00:00 2001 From: mihasya Date: Fri, 6 Apr 2018 11:00:40 -0700 Subject: [PATCH] add race test for EWMA --- ewma_test.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ewma_test.go b/ewma_test.go index 6cadd5d..058ae2d 100644 --- a/ewma_test.go +++ b/ewma_test.go @@ -1,6 +1,11 @@ package metrics -import "testing" +import ( + "math/rand" + "sync" + "testing" + "time" +) func BenchmarkEWMA(b *testing.B) { a := NewEWMA1() @@ -23,6 +28,22 @@ func BenchmarkEWMAParallel(b *testing.B) { }) } +// exercise race detector +func TestEWMAConcurrency(t *testing.T) { + rand.Seed(time.Now().Unix()) + a := NewEWMA1() + wg := &sync.WaitGroup{} + reps := 100 + for i := 0; i < reps; i++ { + wg.Add(1) + go func(ewma EWMA, wg *sync.WaitGroup) { + a.Update(rand.Int63()) + wg.Done() + }(a, wg) + } + wg.Wait() +} + func TestEWMA1(t *testing.T) { a := NewEWMA1() a.Update(3)