Skip to content

TestSummaryDecay() failed #1336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Jumpmanhere opened this issue Aug 29, 2023 · 3 comments
Closed

TestSummaryDecay() failed #1336

Jumpmanhere opened this issue Aug 29, 2023 · 3 comments

Comments

@Jumpmanhere
Copy link

No description provided.

@Jumpmanhere
Copy link
Author

Jumpmanhere commented Aug 29, 2023

When I run the TestSummaryDecay() function of the summary_test.go file every 300 times, there are normally a few times failed.
    Does anyone else encounter this problem?  
    Actually, I'm not so sure about the test logic --- how do we decide the number 20 here as the condition "math.abs(got - want) > 20" 
    and why assign the AgeBucket with the value 10 in this test?

func TestSummaryDecay(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
// More because it depends on timing than because it is particularly long...
}

sum := NewSummary(SummaryOpts{
	Name:       "test_summary",
	Help:       "helpless",
	MaxAge:     100 * time.Millisecond,
	Objectives: map[float64]float64{0.1: 0.001},
	AgeBuckets: 10,
})

m := &dto.Metric{}
i := 0
tick := time.NewTicker(time.Millisecond)
for range tick.C {
	i++
	sum.Observe(float64(i))
	if i%10 == 0 {
		sum.Write(m)
		if got, want := *m.Summary.Quantile[0].Value, math.Max(float64(i)/10, float64(i-90)); math.Abs(got-want) > 20 {
			t.Errorf("%d. got %f, want %f", i, got, want)
		}
		m.Reset()
	}
	if i >= 1000 {
		break
	}
}
tick.Stop()
// Wait for MaxAge without observations and make sure quantiles are NaN.
time.Sleep(100 * time.Millisecond)
sum.Write(m)
if got := *m.Summary.Quantile[0].Value; !math.IsNaN(got) {
	t.Errorf("got %f, want NaN after expiration", got)
}

}

@bwplotka
Copy link
Member

It's indeed flaky - it's covered in #765

Help welcome! - closing this one as dup.

@RubanChristian
Copy link

Try Mar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants