Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Wang committed Sep 19, 2018
1 parent 31cb854 commit 8129b5b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 8 deletions.
2 changes: 1 addition & 1 deletion aggregator/aggregation_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestAggregationKeyEqual(t *testing.T) {
a: aggregationKey{
aggregationID: aggregation.DefaultID,
storagePolicy: policy.NewStoragePolicy(10*time.Second, xtime.Second, 48*time.Hour),
idPrefixSuffixType: WithPrefixWithSuffix,
idPrefixSuffixType: NoPrefixNoSuffix,
},
b: aggregationKey{
aggregationID: aggregation.DefaultID,
Expand Down
47 changes: 45 additions & 2 deletions aggregator/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,50 @@ func TestAggregatorAddMetricMetrics(t *testing.T) {
m.ReportError(errAggregatorShardNotWriteable)
m.ReportError(errWriteNewMetricRateLimitExceeded)
m.ReportError(errWriteValueRateLimitExceeded)
m.ReportError(errors.New("foo"))

snapshot := s.Snapshot()
counters, timers, gauges := snapshot.Counters(), snapshot.Timers(), snapshot.Gauges()

// Validate we count successes and errors correctly.
require.Equal(t, 7, len(counters))
for _, id := range []string{
"testScope.success+",
"testScope.errors+reason=invalid-metric-types",
"testScope.errors+reason=shard-not-owned",
"testScope.errors+reason=shard-not-writeable",
"testScope.errors+reason=value-rate-limit-exceeded",
"testScope.errors+reason=new-metric-rate-limit-exceeded",
"testScope.errors+reason=not-categorized",
} {
c, exists := counters[id]
require.True(t, exists)
require.Equal(t, int64(1), c.Value())
}

// Validate we record times correctly.
require.Equal(t, 1, len(timers))

for _, id := range []string{
"testScope.success-latency+",
} {
ti, exists := timers[id]
require.True(t, exists)
require.Equal(t, []time.Duration{time.Second}, ti.Values())
}

// Validate we do not have any gauges.
require.Equal(t, 0, len(gauges))
}

func TestAggregatorAddTimedMetrics(t *testing.T) {
s := tally.NewTestScope("testScope", nil)
m := newAggregatorAddTimedMetrics(s, 1.0)
m.ReportSuccess(time.Second)
m.ReportError(errShardNotOwned)
m.ReportError(errAggregatorShardNotWriteable)
m.ReportError(errWriteNewMetricRateLimitExceeded)
m.ReportError(errWriteValueRateLimitExceeded)
m.ReportError(errTooFarInTheFuture)
m.ReportError(errTooFarInThePast)
m.ReportError(errors.New("foo"))
Expand All @@ -930,10 +974,9 @@ func TestAggregatorAddMetricMetrics(t *testing.T) {
counters, timers, gauges := snapshot.Counters(), snapshot.Timers(), snapshot.Gauges()

// Validate we count successes and errors correctly.
require.Equal(t, 9, len(counters))
require.Equal(t, 8, len(counters))
for _, id := range []string{
"testScope.success+",
"testScope.errors+reason=invalid-metric-types",
"testScope.errors+reason=shard-not-owned",
"testScope.errors+reason=shard-not-writeable",
"testScope.errors+reason=value-rate-limit-exceeded",
Expand Down
12 changes: 7 additions & 5 deletions aggregator/entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1307,8 +1307,9 @@ func TestEntryAddTimed(t *testing.T) {
require.NoError(t, e.AddTimed(testTimedMetric, testTimedMetadata))
require.Equal(t, 1, len(e.aggregations))
expectedKey := aggregationKey{
aggregationID: testTimedMetadata.AggregationID,
storagePolicy: testTimedMetadata.StoragePolicy,
aggregationID: testTimedMetadata.AggregationID,
storagePolicy: testTimedMetadata.StoragePolicy,
idPrefixSuffixType: NoPrefixNoSuffix,
}
idx := e.aggregations.index(expectedKey)
require.True(t, idx >= 0)
Expand Down Expand Up @@ -1369,8 +1370,9 @@ func TestEntryAddTimed(t *testing.T) {
require.NoError(t, e.AddTimed(metric, metadata))
require.Equal(t, 2, len(e.aggregations))
expectedKeyNew := aggregationKey{
aggregationID: metadata.AggregationID,
storagePolicy: metadata.StoragePolicy,
aggregationID: metadata.AggregationID,
storagePolicy: metadata.StoragePolicy,
idPrefixSuffixType: NoPrefixNoSuffix,
}
idx = e.aggregations.index(expectedKey)
require.True(t, idx >= 0)
Expand Down Expand Up @@ -1490,7 +1492,7 @@ func TestEntryAddForwardedMetricTooLate(t *testing.T) {
metadata := testForwardMetadata
metadata.StoragePolicy = input.storagePolicy
metadata.NumForwardedTimes = input.numForwardedTimes
require.Equal(t, errTooFarInThePast, e.AddForwarded(metric, metadata))
require.Equal(t, errArrivedTooLate, e.AddForwarded(metric, metadata))
}
}

Expand Down

0 comments on commit 8129b5b

Please sign in to comment.