From 9fa1893ed6932494af6d6ce31994354eaebc2313 Mon Sep 17 00:00:00 2001 From: linhai zhu Date: Fri, 16 Feb 2024 14:24:48 -0800 Subject: [PATCH] add test cases --- scope_registry_test.go | 43 +++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/scope_registry_test.go b/scope_registry_test.go index 6ddc2c2..66dc189 100644 --- a/scope_registry_test.go +++ b/scope_registry_test.go @@ -222,21 +222,38 @@ func TestForEachScopeConcurrent(t *testing.T) { <-done } -func TestCachedReporterNoAllocOnOmitInternalMetrics(t *testing.T) { - r := newTestStatsReporter() - root, closer := NewRootScope(ScopeOptions{CachedReporter: r, OmitCardinalityMetrics: true}, 0) - wantGauges := 1 +func TestCachedReporterInternalMetricsAlloc(t *testing.T) { + tests := []struct { + name string + omitCardinalityMetrics bool + wantGauges int + }{ + { + name: "omit metrics", + omitCardinalityMetrics: true, + wantGauges: 1, + }, + { + name: "include metrics", + omitCardinalityMetrics: false, + wantGauges: 1 + numInternalMetrics, + }, + } - s := root.(*scope) + for _, tt := range tests { + r := newTestStatsReporter() + root, closer := NewRootScope(ScopeOptions{CachedReporter: r, OmitCardinalityMetrics: tt.omitCardinalityMetrics}, 0) + s := root.(*scope) - r.gg.Add(wantGauges) - s.Gauge("gauge-foo").Update(3) + r.gg.Add(tt.wantGauges) + s.Gauge("gauge-foo").Update(3) - closer.Close() - r.WaitAll() + closer.Close() + r.WaitAll() - assert.Equal( - t, wantGauges, len(r.gauges), "expected %d gauges, got %d gauges", wantGauges, - len(r.gauges), - ) + assert.Equal( + t, tt.wantGauges, len(r.gauges), "%n: expected %d gauges, got %d gauges", tt.name, tt.wantGauges, + len(r.gauges), + ) + } }