(t *testing.T)
| 371 | } |
| 372 | |
| 373 | func TestSummaryDecay(t *testing.T) { |
| 374 | now := time.Now() |
| 375 | |
| 376 | sum := NewSummary(SummaryOpts{ |
| 377 | Name: "test_summary", |
| 378 | Help: "helpless", |
| 379 | MaxAge: 100 * time.Millisecond, |
| 380 | Objectives: map[float64]float64{0.1: 0.001}, |
| 381 | AgeBuckets: 10, |
| 382 | now: func() time.Time { |
| 383 | return now |
| 384 | }, |
| 385 | }) |
| 386 | |
| 387 | m := &dto.Metric{} |
| 388 | for i := 1; i <= 1000; i++ { |
| 389 | now = now.Add(time.Millisecond) |
| 390 | sum.Observe(float64(i)) |
| 391 | if i%10 == 0 { |
| 392 | sum.Write(m) |
| 393 | got := *m.Summary.Quantile[0].Value |
| 394 | want := math.Max(float64(i)/10, float64(i-90)) |
| 395 | if math.Abs(got-want) > 20 { |
| 396 | t.Errorf("%d. got %f, want %f", i, got, want) |
| 397 | } |
| 398 | m.Reset() |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | // Simulate waiting for MaxAge without observations |
| 403 | now = now.Add(100 * time.Millisecond) |
| 404 | sum.Write(m) |
| 405 | if got := *m.Summary.Quantile[0].Value; !math.IsNaN(got) { |
| 406 | t.Errorf("got %f, want NaN after expiration", got) |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | func getBounds(vars []float64, q, ε float64) (minBound, maxBound float64) { |
| 411 | // TODO(beorn7): This currently tolerates an error of up to 2*ε. The |
nothing calls this directly
no test coverage detected