fix(test): Remove uses of t.FailNow in goroutines (#1978)

It is documented as illegal to use t.FailNow in a goroutine.
Uses of require assertions call t.FailNow. This may have led to
inconsistent test results as some assertions were subject to
undefined behavior. Note that it is still allowed to call
assert assertions in goroutines.

See: https://pkg.go.dev/testing#T.FailNow
This commit is contained in:
Johan Brandhorst-Satzkorn authored and GitHub committed 2022-04-07 09:26:34 -04:00
1 parent 1be55b50c7
commit f2fa1142d3
6 files changed
+86 -41

No files matched your search

+10 -5
View File
@@ -250,13 +250,18 @@ func TestCallbackInterceptor(t *testing.T) {
Handler: wrapHandlerWithCallbackInterceptor(noopHandler, nil),
}
// Use error channel so that we can use test assertions on the returned error.
// It is illegal to call `t.FailNow()` from a goroutine.
// https://pkg.go.dev/testing#T.FailNow
errChan := make(chan error)
go func() {
if err := server.Serve(listener); err != nil {
if err != http.ErrServerClosed {
require.NoError(t, err)
}
}
errChan <- server.Serve(listener)
}()
t.Cleanup(func() {
if err := <-errChan; err != http.ErrServerClosed {
require.NoError(t, err)
}
})
testCases := []struct {
name string