Skip to content

Commit

Permalink
fix race in testutil Accumulator.Wait() (influxdata#2598)
Browse files Browse the repository at this point in the history
  • Loading branch information
phemmer authored and calerogers committed Apr 5, 2017
1 parent 7a35502 commit eb3d559
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 eb3d559

Please sign in to comment.