Skip to content

Commit

Permalink
fix race in testutil Accumulator.Wait() (#2598)
Browse files Browse the repository at this point in the history
  • Loading branch information
phemmer authored and danielnelson committed Mar 30, 2017
1 parent cc5b2f6 commit 03ee602
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions testutil/accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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()
}
Expand Down

0 comments on commit 03ee602

Please sign in to comment.