(t *testing.T)
| 258 | } |
| 259 | |
| 260 | func 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 | |
| 296 | func Test_gauge_demandTracking(t *testing.T) { |
| 297 | g := newGauge("my_gauge", noopLimiter, map[string]string{}, 15*time.Minute) |
nothing calls this directly
no test coverage detected