Skip to content

Commit

Permalink
Fix flaky gRPC server shutdown in tests (#6191)
Browse files Browse the repository at this point in the history
* Use `t.Cleanup(cleanup)` instead of `defer cleanup()`

Which seems to reduce the likelyhood of the flaky gRPC server shutdown

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* Do not fail test if gRPC server graceful shutdown fails

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
  • Loading branch information
chaudum authored May 18, 2022
1 parent 62f5e59 commit 8518560
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions pkg/storage/stores/shipper/gateway_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"log"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -115,19 +114,16 @@ func createTestGrpcServer(t *testing.T) (func(), string) {
indexgatewaypb.RegisterIndexGatewayServer(s, &server)
go func() {
if err := s.Serve(lis); err != nil {
log.Fatalf("Failed to serve: %v", err)
t.Logf("Failed to serve: %v", err)
}
}()
cleanup := func() {
s.GracefulStop()
}

return cleanup, lis.Addr().String()
return s.GracefulStop, lis.Addr().String()
}

func TestGatewayClient(t *testing.T) {
cleanup, storeAddress := createTestGrpcServer(t)
defer cleanup()
t.Cleanup(cleanup)

var cfg IndexGatewayClientConfig
cfg.Mode = indexgateway.SimpleMode
Expand Down Expand Up @@ -313,7 +309,7 @@ func Benchmark_QueriesMatchingLargeNumOfRows(b *testing.B) {
func TestDoubleRegistration(t *testing.T) {
r := prometheus.NewRegistry()
cleanup, storeAddress := createTestGrpcServer(t)
defer cleanup()
t.Cleanup(cleanup)

_, err := NewGatewayClient(IndexGatewayClientConfig{
Address: storeAddress,
Expand Down

0 comments on commit 8518560

Please sign in to comment.