| 270 | } |
| 271 | |
| 272 | func FuzzExemplarsForBlock(f *testing.F) { |
| 273 | f.Add(uint32(100), uint32(60)) // limit = 100, duration = 60s |
| 274 | f.Add(uint32(0), uint32(30)) // limit = 0, duration = 30s |
| 275 | f.Add(uint32(1000), uint32(0)) // limit = 1000, duration = 0s |
| 276 | |
| 277 | s := &queryRangeSharder{} |
| 278 | |
| 279 | f.Fuzz(func(t *testing.T, limit uint32, value uint32) { |
| 280 | now := time.Now() |
| 281 | block := &backend.BlockMeta{ |
| 282 | BlockID: backend.MustParse(uuid.NewString()), |
| 283 | StartTime: now.Add(-time.Duration(value) * time.Second), |
| 284 | EndTime: now, |
| 285 | } |
| 286 | |
| 287 | totalDurationNanos := int64(value) * 1e9 |
| 288 | result := s.exemplarsForBlock(block, limit, totalDurationNanos) |
| 289 | |
| 290 | if limit == 0 || value == 0 { |
| 291 | assert.Equal(t, uint32(0), result, "result should be 0") |
| 292 | } else { |
| 293 | assert.Greater(t, result, uint32(0), "result should be greater than 0") |
| 294 | } |
| 295 | }) |
| 296 | } |
| 297 | |
| 298 | // nolint: gosec // G115 |
| 299 | func TestExemplarsCutoff(t *testing.T) { |