Skip to content

Commit

Permalink
Merge pull request #126 from palantir/touchUpTests
Browse files Browse the repository at this point in the history
Touch up tests
  • Loading branch information
bmoylan authored Dec 2, 2018
2 parents f492be0 + 6fd2503 commit 5f368c8
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions metrics/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,39 +208,39 @@ func TestSubregistry_Unregister(t *testing.T) {
registry.Gauge("gauge1", metrics.MustNewTag("tagKey", "tagValue1")).Update(0)
registry.Gauge("gauge1", metrics.MustNewTag("tagKey", "tagValue2")).Update(0)
registry.Gauge("gauge2").Update(0)
assert.True(t, registryContains(t, registry, "gauge1", []metrics.Tag{metrics.MustNewTag("tagKey", "tagValue1")}))
assert.True(t, registryContains(t, registry, "gauge1", []metrics.Tag{metrics.MustNewTag("tagKey", "tagValue2")}))
assert.True(t, registryContains(t, registry, "gauge2", nil))
assert.Equal(t, 3, registrySize(t, registry))
assert.True(t, registryContains(registry, "gauge1", []metrics.Tag{metrics.MustNewTag("tagKey", "tagValue1")}))
assert.True(t, registryContains(registry, "gauge1", []metrics.Tag{metrics.MustNewTag("tagKey", "tagValue2")}))
assert.True(t, registryContains(registry, "gauge2", nil))
assert.Equal(t, 3, registrySize(registry))
registry.Unregister("gauge1", metrics.MustNewTag("tagKey", "tagValue1"))
assert.True(t, registryContains(t, registry, "gauge1", []metrics.Tag{metrics.MustNewTag("tagKey", "tagValue2")}))
assert.True(t, registryContains(t, registry, "gauge2", nil))
assert.Equal(t, 2, registrySize(t, registry))
assert.True(t, registryContains(registry, "gauge1", []metrics.Tag{metrics.MustNewTag("tagKey", "tagValue2")}))
assert.True(t, registryContains(registry, "gauge2", nil))
assert.Equal(t, 2, registrySize(registry))
registry.Unregister("gauge1", metrics.MustNewTag("tagKey", "tagValue2"))
assert.True(t, registryContains(t, registry, "gauge2", nil))
assert.Equal(t, 1, registrySize(t, registry))
assert.True(t, registryContains(registry, "gauge2", nil))
assert.Equal(t, 1, registrySize(registry))
registry.Unregister("gauge2")
assert.Equal(t, 0, registrySize(t, registry))
assert.Equal(t, 0, registrySize(registry))
}

func TestRootRegistry_Unregister(t *testing.T) {
registry := metrics.NewRootMetricsRegistry()
registry.Gauge("gauge1", metrics.MustNewTag("tagKey", "tagValue1")).Update(0)
registry.Gauge("gauge1", metrics.MustNewTag("tagKey", "tagValue2")).Update(0)
registry.Gauge("gauge2").Update(0)
assert.True(t, registryContains(t, registry, "gauge1", []metrics.Tag{metrics.MustNewTag("tagKey", "tagValue1")}))
assert.True(t, registryContains(t, registry, "gauge1", []metrics.Tag{metrics.MustNewTag("tagKey", "tagValue2")}))
assert.True(t, registryContains(t, registry, "gauge2", nil))
assert.Equal(t, 3, registrySize(t, registry))
assert.True(t, registryContains(registry, "gauge1", []metrics.Tag{metrics.MustNewTag("tagKey", "tagValue1")}))
assert.True(t, registryContains(registry, "gauge1", []metrics.Tag{metrics.MustNewTag("tagKey", "tagValue2")}))
assert.True(t, registryContains(registry, "gauge2", nil))
assert.Equal(t, 3, registrySize(registry))
registry.Unregister("gauge1", metrics.MustNewTag("tagKey", "tagValue1"))
assert.True(t, registryContains(t, registry, "gauge1", []metrics.Tag{metrics.MustNewTag("tagKey", "tagValue2")}))
assert.True(t, registryContains(t, registry, "gauge2", nil))
assert.Equal(t, 2, registrySize(t, registry))
assert.True(t, registryContains(registry, "gauge1", []metrics.Tag{metrics.MustNewTag("tagKey", "tagValue2")}))
assert.True(t, registryContains(registry, "gauge2", nil))
assert.Equal(t, 2, registrySize(registry))
registry.Unregister("gauge1", metrics.MustNewTag("tagKey", "tagValue2"))
assert.True(t, registryContains(t, registry, "gauge2", nil))
assert.Equal(t, 1, registrySize(t, registry))
assert.True(t, registryContains(registry, "gauge2", nil))
assert.Equal(t, 1, registrySize(registry))
registry.Unregister("gauge2")
assert.Equal(t, 0, registrySize(t, registry))
assert.Equal(t, 0, registrySize(registry))
}

func TestRootRegistry_ConcurrentUnregisterAndEachDoesNotPanic(t *testing.T) {
Expand Down Expand Up @@ -315,22 +315,22 @@ func TestRootRegistry_SubregistryWithTags(t *testing.T) {
}))
}

func registrySize(t *testing.T, registry metrics.Registry) int {
func registrySize(registry metrics.Registry) int {
count := 0
registry.Each(metrics.MetricVisitor(func(name string, tags metrics.Tags, metric metrics.MetricVal) {
count++
}))
return count
}

func registryContains(t *testing.T, registry metrics.Registry, name string, tags metrics.Tags) bool {
func registryContains(registry metrics.Registry, name string, tags metrics.Tags) bool {
contains := false
tagStrings := []string{}
var tagStrings []string
for _, tag := range tags {
tagStrings = append(tagStrings, tag.String())
}
registry.Each(metrics.MetricVisitor(func(eachName string, eachTags metrics.Tags, metric metrics.MetricVal) {
eachTagStrings := []string{}
var eachTagStrings []string
for _, eachTag := range eachTags {
eachTagStrings = append(eachTagStrings, eachTag.String())
}
Expand Down

0 comments on commit 5f368c8

Please sign in to comment.