From f13686bdf72fa9cdfed26fff7ab8141f9beeeecf Mon Sep 17 00:00:00 2001 From: Patrick Hemmer Date: Wed, 29 Mar 2017 20:03:06 -0400 Subject: [PATCH] fix race in testutil Accumulator.Wait() (#2598) --- testutil/accumulator.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testutil/accumulator.go b/testutil/accumulator.go index b958e8cc9..9ebf77cf7 100644 --- a/testutil/accumulator.go +++ b/testutil/accumulator.go @@ -43,9 +43,9 @@ func (a *Accumulator) NMetrics() uint64 { } func (a *Accumulator) ClearMetrics() { - atomic.StoreUint64(&a.nMetrics, 0) a.Lock() defer a.Unlock() + atomic.StoreUint64(&a.nMetrics, 0) a.Metrics = make([]*Metric, 0) } @@ -56,9 +56,9 @@ func (a *Accumulator) AddFields( tags map[string]string, timestamp ...time.Time, ) { - atomic.AddUint64(&a.nMetrics, 1) a.Lock() defer a.Unlock() + atomic.AddUint64(&a.nMetrics, 1) if a.Cond != nil { a.Cond.Broadcast() }