MCPcopy
hub / github.com/prometheus/client_golang / TestGatherDoesNotLeakGoroutines

Function TestGatherDoesNotLeakGoroutines

prometheus/registry_test.go:1344–1367  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1342}
1343
1344func TestGatherDoesNotLeakGoroutines(t *testing.T) {
1345 // Use goleak to verify that no unexpected goroutines are leaked during the test.
1346 defer goleak.VerifyNone(t)
1347
1348 // Create a new Prometheus registry without any default collectors.
1349 reg := prometheus.NewRegistry()
1350
1351 // Register 100 simple Gauge metrics with distinct names and constant labels.
1352 for i := 0; i < 100; i++ {
1353 reg.MustRegister(prometheus.NewGauge(prometheus.GaugeOpts{
1354 Name: "test_metric_" + string(rune(i)),
1355 Help: "Test metric",
1356 ConstLabels: prometheus.Labels{"id": string(rune(i))},
1357 }))
1358 }
1359
1360 // Call Gather repeatedly to simulate stress and check for potential goroutine leaks.
1361 for i := 0; i < 1000; i++ {
1362 _, err := reg.Gather()
1363 if err != nil {
1364 t.Fatalf("unexpected error from Gather: %v", err)
1365 }
1366 }
1367}

Callers

nothing calls this directly

Calls 4

MustRegisterMethod · 0.95
GatherMethod · 0.95
NewRegistryFunction · 0.92
NewGaugeFunction · 0.92

Tested by

no test coverage detected