@@ -90,6 +90,11 @@ func TestReadMetricsConsistency(t *testing.T) {
90
90
// things (e.g. allocating) so what we read can't reasonably compared
91
91
// to runtime values.
92
92
93
+ // Run a few GC cycles to get some of the stats to be non-zero.
94
+ runtime .GC ()
95
+ runtime .GC ()
96
+ runtime .GC ()
97
+
93
98
// Read all the supported metrics through the metrics package.
94
99
descs , samples := prepareAllMetricsSamples ()
95
100
metrics .Read (samples )
@@ -102,6 +107,10 @@ func TestReadMetricsConsistency(t *testing.T) {
102
107
alloc , free * metrics.Float64Histogram
103
108
total uint64
104
109
}
110
+ var gc struct {
111
+ numGC uint64
112
+ pauses uint64
113
+ }
105
114
for i := range samples {
106
115
kind := samples [i ].Value .Kind ()
107
116
if want := descs [samples [i ].Name ].Kind ; kind != want {
@@ -128,6 +137,14 @@ func TestReadMetricsConsistency(t *testing.T) {
128
137
objects .alloc = samples [i ].Value .Float64Histogram ()
129
138
case "/gc/heap/frees-by-size:objects" :
130
139
objects .free = samples [i ].Value .Float64Histogram ()
140
+ case "/gc/cycles:gc-cycles" :
141
+ gc .numGC = samples [i ].Value .Uint64 ()
142
+ case "/gc/pauses:seconds" :
143
+ h := samples [i ].Value .Float64Histogram ()
144
+ gc .pauses = 0
145
+ for i := range h .Counts {
146
+ gc .pauses += h .Counts [i ]
147
+ }
131
148
}
132
149
}
133
150
if totalVirtual .got != totalVirtual .want {
@@ -159,6 +176,11 @@ func TestReadMetricsConsistency(t *testing.T) {
159
176
}
160
177
}
161
178
}
179
+ // The current GC has at least 2 pauses per GC.
180
+ // Check to see if that value makes sense.
181
+ if gc .pauses < gc .numGC * 2 {
182
+ t .Errorf ("fewer pauses than expected: got %d, want at least %d" , gc .pauses , gc .numGC * 2 )
183
+ }
162
184
}
163
185
164
186
func BenchmarkReadMetricsLatency (b * testing.B ) {
0 commit comments