@@ -371,39 +371,36 @@ func TestSummaryVecConcurrency(t *testing.T) {
371371}
372372
373373func TestSummaryDecay (t * testing.T ) {
374- if testing .Short () {
375- t .Skip ("Skipping test in short mode." )
376- // More because it depends on timing than because it is particularly long...
377- }
374+ now := time .Now ()
378375
379376 sum := NewSummary (SummaryOpts {
380377 Name : "test_summary" ,
381378 Help : "helpless" ,
382379 MaxAge : 100 * time .Millisecond ,
383380 Objectives : map [float64 ]float64 {0.1 : 0.001 },
384381 AgeBuckets : 10 ,
382+ now : func () time.Time {
383+ return now
384+ },
385385 })
386386
387387 m := & dto.Metric {}
388- i := 0
389- tick := time .NewTicker (time .Millisecond )
390- for range tick .C {
391- i ++
388+ for i := 1 ; i <= 1000 ; i ++ {
389+ now = now .Add (time .Millisecond )
392390 sum .Observe (float64 (i ))
393391 if i % 10 == 0 {
394392 sum .Write (m )
395- if got , want := * m .Summary .Quantile [0 ].Value , math .Max (float64 (i )/ 10 , float64 (i - 90 )); math .Abs (got - want ) > 20 {
393+ got := * m .Summary .Quantile [0 ].Value
394+ want := math .Max (float64 (i )/ 10 , float64 (i - 90 ))
395+ if math .Abs (got - want ) > 20 {
396396 t .Errorf ("%d. got %f, want %f" , i , got , want )
397397 }
398398 m .Reset ()
399399 }
400- if i >= 1000 {
401- break
402- }
403400 }
404- tick . Stop ()
405- // Wait for MaxAge without observations and make sure quantiles are NaN.
406- time . Sleep (100 * time .Millisecond )
401+
402+ // Simulate waiting for MaxAge without observations
403+ now = now . Add (100 * time .Millisecond )
407404 sum .Write (m )
408405 if got := * m .Summary .Quantile [0 ].Value ; ! math .IsNaN (got ) {
409406 t .Errorf ("got %f, want NaN after expiration" , got )
0 commit comments