From c9ec35e05d632a056f7f71db7d986401c0c65198 Mon Sep 17 00:00:00 2001 From: Christian Haudum Date: Wed, 18 May 2022 12:15:03 +0200 Subject: [PATCH 1/2] 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 --- pkg/storage/stores/shipper/gateway_client_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/storage/stores/shipper/gateway_client_test.go b/pkg/storage/stores/shipper/gateway_client_test.go index 83c3c5340636..a259744b8c7b 100644 --- a/pkg/storage/stores/shipper/gateway_client_test.go +++ b/pkg/storage/stores/shipper/gateway_client_test.go @@ -118,16 +118,13 @@ func createTestGrpcServer(t *testing.T) (func(), string) { log.Fatalf("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 @@ -313,7 +310,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, From 1027bfefca417ed7c764054c93c4a3231ced17d2 Mon Sep 17 00:00:00 2001 From: Christian Haudum Date: Wed, 18 May 2022 13:35:57 +0200 Subject: [PATCH 2/2] Do not fail test if gRPC server graceful shutdown fails Signed-off-by: Christian Haudum --- pkg/storage/stores/shipper/gateway_client_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/storage/stores/shipper/gateway_client_test.go b/pkg/storage/stores/shipper/gateway_client_test.go index a259744b8c7b..387f53e409c7 100644 --- a/pkg/storage/stores/shipper/gateway_client_test.go +++ b/pkg/storage/stores/shipper/gateway_client_test.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "log" "net" "os" "path/filepath" @@ -115,7 +114,7 @@ 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) } }()