Skip to content

Commit

Permalink
add race test for EWMA
Browse files Browse the repository at this point in the history
  • Loading branch information
mihasya committed Apr 6, 2018
1 parent 9073533 commit 4cdad2c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion ewma_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package metrics

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

func BenchmarkEWMA(b *testing.B) {
a := NewEWMA1()
Expand All @@ -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)
Expand Down

0 comments on commit 4cdad2c

Please sign in to comment.