Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ UUID
Unmarshalers
XYZ
YAML
- "dependending" - should be "depending"
- "logics" - should be "logic" (uncountable noun)
- "maintainance" - should be "maintenance"
ad'hoc
agentic
allocs
Expand Down
33 changes: 26 additions & 7 deletions internal/leak/leak.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import (

const labelKey = "testify-leak-check"

const (
maxAttempts = 20
maxWait = 100 * time.Millisecond
waitFactor = 2
)

func init() { //nolint:gochecknoinits // this init check is justify by the use of an internal volatile API.
// check that the profile API behaves as expected or panic.
//
Expand All @@ -42,6 +48,24 @@ func init() { //nolint:gochecknoinits // this init check is justify by the use o
needle := buildNeedle(id)
profile := captureProfile()
match := extractLabeledBlocks(profile, needle)
if match == "" {
// goroutine may not be scheduled yet: wait a bit before taking a decision

wait := time.Microsecond
for range maxAttempts {
time.Sleep(wait) // brief retry: goroutines may be mid-exit.
profile = captureProfile()
match = extractLabeledBlocks(profile, needle)
if match != "" {
break
}

// retry — goroutine might still be exiting
// wait exponential backoff, capped to maxWait
wait = min(wait*waitFactor, maxWait)
}
}

close(blocker)
wg.Wait()
if match == "" {
Expand Down Expand Up @@ -69,16 +93,11 @@ func Leaked(ctx context.Context, tested func()) string {
return "" // early exit: clean state
}

const (
maxAttempts = 20
maxWait = 100 * time.Millisecond
waitFactor = 2
)
wait := time.Microsecond
for range maxAttempts {
time.Sleep(wait) // brief retry: goroutines may be mid-exit.
profile := captureProfile()
match := extractLabeledBlocks(profile, needle)
profile = captureProfile()
match = extractLabeledBlocks(profile, needle)
if match == "" {
return "" // clean
}
Expand Down
Loading