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
fix: goroutine leak #5364
fix: goroutine leak #5364
Changes from all commits
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/goleak" | ||
. "sigs.k8s.io/kustomize/api/internal/utils" | ||
) | ||
|
||
|
@@ -62,3 +63,20 @@ func TestTimedCallSlowWithError(t *testing.T) { | |
t.Fail() | ||
} | ||
} | ||
|
||
func TestTimedCallGoroutineLeak(t *testing.T) { | ||
defer goleak.VerifyNone(t) | ||
err := TimedCall("function done, no goroutine leaks", timeToWait, func() error { | ||
time.Sleep(tooSlow) | ||
return fmt.Errorf("function done") | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you be more specify on what has not done? it would help a lot. Thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the misrepresentation here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I‘m not buying just return nil, I think something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion, the code has been changed to |
||
if assert.Error(t, err) { | ||
assert.EqualError(t, err, errMsg("function done, no goroutine leaks")) | ||
} else { | ||
t.Fail() | ||
} | ||
|
||
// The code introduces a 2-second sleep to allow the goroutine to complete its execution. | ||
// Subsequently, it verifies if the goroutine created by the function exits as expected. | ||
time.Sleep(tooSlow) | ||
} |
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.
Adding a note here for other reviewers: I double checked if this dependency is OK by checking the allowlist here . MIT licenses are allowed, which looks like this repo is covered under, so this should be OK.
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 also check k/k, most of the deps on it are MIT and apache2. so I think
goleak
from uber which MIT license as well will be OK.