MCPcopy
hub / github.com/grafana/tempo / Test_gauge_concurrencyCorrectness

Function Test_gauge_concurrencyCorrectness

modules/generator/registry/gauge_test.go:260–294  ·  modules/generator/registry/gauge_test.go::Test_gauge_concurrencyCorrectness
(t *testing.T)

Source from the content-addressed store, hash-verified

258}
259
260func Test_gauge_concurrencyCorrectness(t *testing.T) {
261 c := newGauge("my_gauge", noopLimiter, map[string]string{}, 15*time.Minute)
262
263 var wg sync.WaitGroup
264 end := make(chan struct{})
265
266 totalCount := atomic.NewUint64(0)
267
268 for i := 0; i < 4; i++ {
269 wg.Add(1)
270 go func() {
271 defer wg.Done()
272 for {
273 select {
274 case <-end:
275 return
276 default:
277 c.Inc(buildTestLabels([]string{"label"}, []string{"value-1"}), 1.0)
278 totalCount.Inc()
279 }
280 }
281 }()
282 }
283
284 time.Sleep(200 * time.Millisecond)
285 close(end)
286
287 wg.Wait()
288
289 collectionTimeMs := time.Now().UnixMilli()
290 expectedSamples := []sample{
291 newSample(map[string]string{"__name__": "my_gauge", "label": "value-1"}, collectionTimeMs, float64(totalCount.Load())),
292 }
293 collectMetricAndAssert(t, c, collectionTimeMs, 1, expectedSamples, nil)
294}
295
296func Test_gauge_demandTracking(t *testing.T) {
297 g := newGauge("my_gauge", noopLimiter, map[string]string{}, 15*time.Minute)

Callers

nothing calls this directly

Calls 10

newGaugeFunction · 0.85
buildTestLabelsFunction · 0.85
newSampleFunction · 0.85
collectMetricAndAssertFunction · 0.85
AddMethod · 0.65
DoneMethod · 0.65
IncMethod · 0.65
SleepMethod · 0.65
WaitMethod · 0.65
NowMethod · 0.65

Tested by

no test coverage detected