Skip to content

Commit e6b0793

Browse files
committed
fix(Eventually): fixed go routine leak issues
Reference (original issue report): stretchr#1611 This fix involves a complete rewrite of assertions that run background checks, with more idiomatic go routine codes and use of context.Context. Affected assertions: * Eventually * Never * EventuallyWithT We no longer run go routines that are not waited for. Timeouts and early exits are handled via context.Context. CollecT.FailNow() now also cancels the context of the caller instead. Significant changes: * callers should not expect Eventually and others to complete in the case of a blocking condition function. In particular, the condition function should never wait for an event that is triggered after Eventually. Complex or long-running condition function may use t.Context() to exit early if the test is failed. * callers may safely assume that only one go routine is executing the condition function (no race on writes) * test: asserted stretch/testify#480 is fixed Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent c217cc4 commit e6b0793

6 files changed

Lines changed: 759 additions & 290 deletions

File tree

internal/assertions/compare_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package assertions
55

66
import (
77
"bytes"
8-
"fmt"
98
"iter"
109
"runtime"
1110
"slices"
@@ -194,24 +193,6 @@ func TestCompareMsgAndArgsForwarding(t *testing.T) {
194193
}
195194
}
196195

197-
type outputT struct {
198-
buf *bytes.Buffer
199-
helpers map[string]struct{}
200-
}
201-
202-
// Implements T.
203-
func (t *outputT) Errorf(format string, args ...any) {
204-
s := fmt.Sprintf(format, args...)
205-
t.buf.WriteString(s)
206-
}
207-
208-
func (t *outputT) Helper() {
209-
if t.helpers == nil {
210-
t.helpers = make(map[string]struct{})
211-
}
212-
t.helpers[callerName(1)] = struct{}{}
213-
}
214-
215196
// callerName gives the function name (qualified with a package path)
216197
// for the caller after skip frames (where 0 means the current function).
217198
func callerName(skip int) string {

0 commit comments

Comments
 (0)