diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-11 13:34:05 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-09-23 10:02:55 +0300 |
commit | de1d44320173415fcdba41a2b768b08bd6f3aa93 (patch) | |
tree | 73d69f72300b8bede5f7ab6ecda2725f4eb5610a /client | |
parent | 6a5cb67aae77eb8167161bb3b027defdc96caf8f (diff) |
grpc: Fix missing error checks for `Serve()` function
The `grpc.Server.Serve()` function will return an error when the gRPC
server has either failed unexpectedly or in case it wasn't properly shut
down. We don't check this error in many places though, which both causes
the errcheck linter to complain and hides issues we have with some of
our test setups.
Fix the missing error checks via a new `testhelper.MustServe()` helper
function that does the error checking for us. This surfaces some test
errors for tests that forget to shut down the server or that manually
close the listener, which should be handled by gRPC itself. All of those
errors are fixed while at it.
Drop the corresponding linting exceptions.
Diffstat (limited to 'client')
-rw-r--r-- | client/dial_test.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/client/dial_test.go b/client/dial_test.go index b862b4c3e..e0870ee32 100644 --- a/client/dial_test.go +++ b/client/dial_test.go @@ -296,7 +296,7 @@ func TestDial_Correlation(t *testing.T) { } grpc_testing.RegisterTestServiceServer(grpcServer, svc) - go func() { assert.NoError(t, grpcServer.Serve(listener)) }() + go testhelper.MustServe(t, grpcServer, listener) defer grpcServer.Stop() ctx := testhelper.Context(t) @@ -332,7 +332,7 @@ func TestDial_Correlation(t *testing.T) { } grpc_testing.RegisterTestServiceServer(grpcServer, svc) - go func() { assert.NoError(t, grpcServer.Serve(listener)) }() + go testhelper.MustServe(t, grpcServer, listener) defer grpcServer.Stop() ctx := testhelper.Context(t) @@ -395,7 +395,7 @@ func TestDial_Tracing(t *testing.T) { } grpc_testing.RegisterTestServiceServer(grpcServer, svc) - go func() { require.NoError(t, grpcServer.Serve(listener)) }() + go testhelper.MustServe(t, grpcServer, listener) defer grpcServer.Stop() ctx := testhelper.Context(t) @@ -543,7 +543,7 @@ func startTCPListener(tb testing.TB, factory func(credentials.TransportCredentia address := fmt.Sprintf("%d", tcpPort) grpcServer := factory(insecure.NewCredentials()) - go grpcServer.Serve(listener) + go testhelper.MustServe(tb, grpcServer, listener) return func() { grpcServer.Stop() @@ -558,7 +558,7 @@ func startUnixListener(tb testing.TB, factory func(credentials.TransportCredenti require.NoError(tb, err) grpcServer := factory(insecure.NewCredentials()) - go grpcServer.Serve(listener) + go testhelper.MustServe(tb, grpcServer, listener) return func() { grpcServer.Stop() @@ -583,7 +583,7 @@ func startTLSListener(tb testing.TB, factory func(credentials.TransportCredentia MinVersion: tls.VersionTLS12, }), ) - go grpcServer.Serve(listener) + go testhelper.MustServe(tb, grpcServer, listener) return func() { grpcServer.Stop() |