Skip to content

Commit

Permalink
Merge pull request #14 from segmentio/fix-counter-bug
Browse files Browse the repository at this point in the history
fix counter bug
  • Loading branch information
achille-roussel committed Jan 19, 2017
2 parents caa0f0f + 20f6271 commit 9c5126f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion datadog/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func metrics(state []stats.Metric, counters map[string]counter, now time.Time) [
}

counters[m.Key] = counter{
value: value,
value: m.Value,
modTime: now,
}

Expand Down
7 changes: 6 additions & 1 deletion datadog/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func TestServer(t *testing.T) {
ma.Incr()
ma.Incr()

// Test that the counter properly computes the delta between flushes of the
// client.
time.Sleep(10 * time.Millisecond)
ma.Incr()

mb := stats.MakeGauge(engine, "B")
mb.Set(1)
mb.Set(2)
Expand All @@ -57,7 +62,7 @@ func TestServer(t *testing.T) {

time.Sleep(10 * time.Millisecond)

if n := atomic.LoadUint32(&a); n != 2 { // two increments (+1, +1)
if n := atomic.LoadUint32(&a); n != 3 { // two increments (+1, +1, +1)
t.Error("datadog.test.A: bad count:", n)
}

Expand Down

0 comments on commit 9c5126f

Please sign in to comment.