@@ -6,6 +6,29 @@ import (
66 "time"
77)
88
9+ func TestRuntimeMemStatsDoubleRegister (t * testing.T ) {
10+ r := NewRegistry ()
11+ RegisterRuntimeMemStats (r )
12+ storedGauge := r .Get ("runtime.MemStats.LastGC" ).(Gauge )
13+
14+ runtime .GC ()
15+ CaptureRuntimeMemStatsOnce (r )
16+
17+ firstGC := storedGauge .Value ()
18+ if 0 == firstGC {
19+ t .Errorf ("firstGC got %d, expected timestamp > 0" , firstGC )
20+ }
21+
22+ time .Sleep (time .Millisecond )
23+
24+ RegisterRuntimeMemStats (r )
25+ runtime .GC ()
26+ CaptureRuntimeMemStatsOnce (r )
27+ if lastGC := storedGauge .Value (); firstGC == lastGC {
28+ t .Errorf ("lastGC got %d, expected a higher timestamp value" , lastGC )
29+ }
30+ }
31+
932func BenchmarkRuntimeMemStats (b * testing.B ) {
1033 r := NewRegistry ()
1134 RegisterRuntimeMemStats (r )
@@ -86,20 +109,3 @@ func testRuntimeMemStatsBlocking(ch chan int) {
86109 }
87110 }
88111}
89-
90- func TestRuntimeMemStatsDoubleRegister (t * testing.T ) {
91- r := NewRegistry ()
92- RegisterRuntimeMemStats (r )
93- zero := runtimeMetrics .MemStats .NumGC .Value () // Get a "zero" since GC may have run before these tests.
94- runtime .GC ()
95- CaptureRuntimeMemStatsOnce (r )
96-
97- if count := runtimeMetrics .MemStats .NumGC .Value (); 1 != count - zero {
98- t .Errorf ("NumGC got %d, expected 1" , count - zero )
99- }
100-
101- RegisterRuntimeMemStats (r )
102- if count := runtimeMetrics .MemStats .NumGC .Value (); 1 != count - zero {
103- t .Errorf ("NumGC got %d, expected 1" , count - zero )
104- }
105- }
0 commit comments