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:
1 parent
1be55b50c7
commit
f2fa1142d3
6 files changed
+86
-41
No files matched your search
@@ -790,10 +790,17 @@ func startTestGreeterService(t *testing.T, greeter interceptor.GreeterServiceSer
|
||||
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(interceptors...)),
|
||||
)
|
||||
interceptor.RegisterGreeterServiceServer(s, greeter)
|
||||
// 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() {
|
||||
err := s.Serve(listener)
|
||||
require.NoError(err)
|
||||
errChan <- s.Serve(listener)
|
||||
}()
|
||||
t.Cleanup(func() {
|
||||
// Will block until we stopped serving
|
||||
require.NoError(<-errChan)
|
||||
})
|
||||
|
||||
conn, _ := grpc.DialContext(dialCtx, "", grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) {
|
||||
return listener.Dial()
|
||||
|
||||
Reference in new issue
Block a user