Fix metrics test reentrance (#1680)

if we clean the view we get success.
Also verify initial size is 0
This commit is contained in:
Victor Agababov 2020-09-02 15:15:31 -07:00 committed by GitHub
parent 2ee0e98803
commit b0307fc6d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -402,7 +402,13 @@ func TestMetricFetch(t *testing.T) {
TagKeys: []tag.Key{tagKey},
}
m := GetMetric("count")
if len(m) != 0 {
t.Errorf("Unexpected number of found metrics (%d): %+v", len(m), m)
}
view.Register(countView)
t.Cleanup(func() { view.Unregister(countView) })
ctx, err := tag.New(context.Background(), tag.Upsert(tagKey, "alpha"))
if err != nil {
@ -420,8 +426,8 @@ func TestMetricFetch(t *testing.T) {
}
stats.Record(ctx, count.M(20))
EnsureRecorded()
m := GetMetric("count")
m = GetMetric("count")
if len(m) != 1 {
t.Errorf("Unexpected number of found metrics (%d): %+v", len(m), m)
}