Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touch up tests #126

Merged
merged 1 commit into from
Dec 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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