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

Method TestPanic

experimental/stats/metricregistry_test.go:40–59  ·  view source on GitHub ↗

TestPanic tests that registering two metrics with the same name across any type of metric triggers a panic.

(t *testing.T)

Source from the content-addressed store, hash-verified

38// TestPanic tests that registering two metrics with the same name across any
39// type of metric triggers a panic.
40func (s) TestPanic(t *testing.T) {
41 cleanup := snapshotMetricsRegistryForTesting()
42 defer cleanup()
43
44 want := "metric simple counter already registered"
45 defer func() {
46 if r := recover(); !strings.Contains(fmt.Sprint(r), want) {
47 t.Errorf("expected panic contains %q, got %q", want, r)
48 }
49 }()
50 desc := MetricDescriptor{
51 // Type is not expected to be set from the registerer, but meant to be
52 // set by the metric registry.
53 Name: "simple counter",
54 Description: "number of times recorded on tests",
55 Unit: "{call}",
56 }
57 RegisterInt64Count(desc)
58 RegisterInt64Gauge(desc)
59}
60
61// TestInstrumentRegistry tests the metric registry. It registers testing only
62// metrics using the metric registry, and creates a fake metrics recorder which

Callers

nothing calls this directly

Calls 4

RegisterInt64CountFunction · 0.85
RegisterInt64GaugeFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected