MCPcopy
hub / github.com/grpc/grpc-go / TestNumerousIntCounts

Method TestNumerousIntCounts

experimental/stats/metricregistry_test.go:197–255  ·  view source on GitHub ↗

TestNumerousIntCounts tests numerous int count metrics registered onto the metric registry. A component (simulated by test) should be able to record on the different registered int count metrics.

(t *testing.T)

Source from the content-addressed store, hash-verified

195// metric registry. A component (simulated by test) should be able to record on
196// the different registered int count metrics.
197func (s) TestNumerousIntCounts(t *testing.T) {
198 cleanup := snapshotMetricsRegistryForTesting()
199 defer cleanup()
200
201 intCountHandle1 := RegisterInt64Count(MetricDescriptor{
202 Name: "int counter",
203 Description: "sum of all emissions from tests",
204 Unit: "int",
205 Labels: []string{"int counter label"},
206 OptionalLabels: []string{"int counter optional label"},
207 Default: false,
208 })
209 intCountHandle2 := RegisterInt64Count(MetricDescriptor{
210 Name: "int counter 2",
211 Description: "sum of all emissions from tests",
212 Unit: "int",
213 Labels: []string{"int counter label"},
214 OptionalLabels: []string{"int counter optional label"},
215 Default: false,
216 })
217 intCountHandle3 := RegisterInt64Count(MetricDescriptor{
218 Name: "int counter 3",
219 Description: "sum of all emissions from tests",
220 Unit: "int",
221 Labels: []string{"int counter label"},
222 OptionalLabels: []string{"int counter optional label"},
223 Default: false,
224 })
225
226 fmr := newFakeMetricsRecorder(t)
227
228 intCountHandle1.Record(fmr, 1, []string{"some label value", "some optional label value"}...)
229 got := []int64{fmr.intValues[intCountHandle1.Descriptor()], fmr.intValues[intCountHandle2.Descriptor()], fmr.intValues[intCountHandle3.Descriptor()]}
230 want := []int64{1, 0, 0}
231 if diff := cmp.Diff(got, want); diff != "" {
232 t.Fatalf("fmr.intValues (-got, +want): %v", diff)
233 }
234
235 intCountHandle2.Record(fmr, 1, []string{"some label value", "some optional label value"}...)
236 got = []int64{fmr.intValues[intCountHandle1.Descriptor()], fmr.intValues[intCountHandle2.Descriptor()], fmr.intValues[intCountHandle3.Descriptor()]}
237 want = []int64{1, 1, 0}
238 if diff := cmp.Diff(got, want); diff != "" {
239 t.Fatalf("fmr.intValues (-got, +want): %v", diff)
240 }
241
242 intCountHandle3.Record(fmr, 1, []string{"some label value", "some optional label value"}...)
243 got = []int64{fmr.intValues[intCountHandle1.Descriptor()], fmr.intValues[intCountHandle2.Descriptor()], fmr.intValues[intCountHandle3.Descriptor()]}
244 want = []int64{1, 1, 1}
245 if diff := cmp.Diff(got, want); diff != "" {
246 t.Fatalf("fmr.intValues (-got, +want): %v", diff)
247 }
248
249 intCountHandle3.Record(fmr, 1, []string{"some label value", "some optional label value"}...)
250 got = []int64{fmr.intValues[intCountHandle1.Descriptor()], fmr.intValues[intCountHandle2.Descriptor()], fmr.intValues[intCountHandle3.Descriptor()]}
251 want = []int64{1, 1, 2}
252 if diff := cmp.Diff(got, want); diff != "" {
253 t.Fatalf("fmr.intValues (-got, +want): %v", diff)
254 }

Callers

nothing calls this directly

Calls 6

RegisterInt64CountFunction · 0.85
newFakeMetricsRecorderFunction · 0.85
DescriptorMethod · 0.65
FatalfMethod · 0.65
RecordMethod · 0.45

Tested by

no test coverage detected