Add locking to test accumulator
This commit is contained in:
parent
3ae5b4b280
commit
9cccf8f88a
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Point defines a single point measurement
|
// Point defines a single point measurement
|
||||||
|
@ -16,11 +17,14 @@ type Point struct {
|
||||||
|
|
||||||
// Accumulator defines a mocked out accumulator
|
// Accumulator defines a mocked out accumulator
|
||||||
type Accumulator struct {
|
type Accumulator struct {
|
||||||
|
sync.Mutex
|
||||||
Points []*Point
|
Points []*Point
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add adds a measurement point to the accumulator
|
// Add adds a measurement point to the accumulator
|
||||||
func (a *Accumulator) Add(measurement string, value interface{}, tags map[string]string) {
|
func (a *Accumulator) Add(measurement string, value interface{}, tags map[string]string) {
|
||||||
|
a.Lock()
|
||||||
|
defer a.Unlock()
|
||||||
if tags == nil {
|
if tags == nil {
|
||||||
tags = map[string]string{}
|
tags = map[string]string{}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue