Skip to content

Commit

Permalink
Gauges in the mock sink should store the value not add to it (#111)
Browse files Browse the repository at this point in the history
* Gauges in the mock sink should store the value not add to it

* Fix tests for mock sink gauges
  • Loading branch information
almost authored Jan 18, 2022
1 parent c412bd1 commit 3c8ab33
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mock/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (s *Sink) FlushGauge(name string, val uint64) {
v, _ = gauges.LoadOrStore(name, new(entry))
}
p := v.(*entry)
atomic.AddUint64(&p.val, val)
atomic.StoreUint64(&p.val, val)
atomic.AddInt64(&p.count, 1)
}

Expand Down
4 changes: 1 addition & 3 deletions mock/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ func TestSink_ThreadSafe(t *testing.T) {
gaugeCalls = new(int64)
timerCalls = new(int64)
counterVal = new(uint64)
gaugeVal = new(uint64)
)
funcs := [...]func(){
func() {
Expand All @@ -261,7 +260,6 @@ func TestSink_ThreadSafe(t *testing.T) {
},
func() {
atomic.AddInt64(gaugeCalls, 1)
atomic.AddUint64(gaugeVal, 1)
sink.FlushGauge("name", 1)
},
func() {
Expand Down Expand Up @@ -290,7 +288,7 @@ func TestSink_ThreadSafe(t *testing.T) {
sink.AssertTimerCallCount(t, "name", int(atomic.LoadInt64(timerCalls)))

sink.AssertCounterEquals(t, "name", atomic.LoadUint64(counterVal))
sink.AssertGaugeEquals(t, "name", atomic.LoadUint64(gaugeVal))
sink.AssertGaugeEquals(t, "name", uint64(1))
}

func TestSink_ThreadSafe_Reset(t *testing.T) {
Expand Down

0 comments on commit 3c8ab33

Please sign in to comment.