(t *testing.T)
| 1342 | } |
| 1343 | |
| 1344 | func 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 | } |
nothing calls this directly
no test coverage detected