-
Notifications
You must be signed in to change notification settings - Fork 4.7k
leakcheck: Fix flaky test TestCheck #8309
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
Changes from 1 commit
f4a565e
67f7beb
9af90a0
01e4247
baf4db3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,10 +23,14 @@ import ( | |||||||||
| "fmt" | ||||||||||
| "strings" | ||||||||||
| "sync" | ||||||||||
|
|
||||||||||
| // "sync" | ||||||||||
|
|
||||||||||
| "testing" | ||||||||||
| "time" | ||||||||||
|
|
||||||||||
| "google.golang.org/grpc/internal" | ||||||||||
| // "google.golang.osrg/grpc/internal" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| type testLogger struct { | ||||||||||
|
|
@@ -47,16 +51,14 @@ func TestCheck(t *testing.T) { | |||||||||
| for i := 0; i < leakCount; i++ { | ||||||||||
| go func() { time.Sleep(2 * time.Second) }() | ||||||||||
|
||||||||||
| } | ||||||||||
| if ig := interestingGoroutines(); len(ig) == 0 { | ||||||||||
| t.Error("blah") | ||||||||||
| if leaked := interestingGoroutines(); len(leaked) != leakCount { | ||||||||||
| t.Errorf("interestingGoroutines found %v leaks, want %v leaks", len(leaked), leakCount) | ||||||||||
dfawley marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
| } | ||||||||||
| e := &testLogger{} | ||||||||||
| ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||||||||||
| defer cancel() | ||||||||||
| CheckGoroutines(ctx, e) | ||||||||||
| if e.errorCount != leakCount { | ||||||||||
| if CheckGoroutines(ctx, e); e.errorCount == 0 { | ||||||||||
|
||||||||||
| if CheckGoroutines(ctx, e); e.errorCount == 0 { | |
| if CheckGoroutines(ctx, e); ctx.Err() == nil { |
Or even:
| if CheckGoroutines(ctx, e); e.errorCount == 0 { | |
| if CheckGoroutines(ctx, e); e.errorCount < 3 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check expects that the goroutines spawned by time.Sleep() should still be alive.
I have not put e.errorcount == 3, because ctx can cause its goroutine live longer and it will cause a errorcount of 4 (Because of this the test was flaky)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not put e.errorcount == 3, because ctx can cause its goroutine live longer and it will cause a errorcount of 4
Right, which is why I suggested changing to failing if it's less than three. We should have at least three. Or we can just confirm the check failed by checking ctx.Err() and then not have to worry about all the complexity to track errorCount at all. Either way is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, which is why I suggested changing to failing if it's less than three. We should have at least three. Or we can just confirm the check failed by checking
ctx.Err()and then not have to worry about all the complexity to trackerrorCountat all. Either way is fine.
Right, make sense. Both works fine. I'm going with e.errorcount < 3for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this and below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.