Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid failing tests on gRPC server shutdown errors #8060

Merged
merged 1 commit into from
Jan 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ func server(t *testing.T, h *GRPCRequestHandler) (compactor_client_grpc.Compacto

compactor_client_grpc.RegisterCompactorServer(baseServer, h)
go func() {
require.NoError(t, baseServer.Serve(lis))
if err := baseServer.Serve(lis); err != nil {
t.Logf("Failed to serve: %v", err)
}
}()

conn, err := grpc.DialContext(context.Background(), "",
Expand All @@ -44,7 +46,7 @@ func server(t *testing.T, h *GRPCRequestHandler) (compactor_client_grpc.Compacto

closer := func() {
require.NoError(t, lis.Close())
baseServer.Stop()
baseServer.GracefulStop()
}

client := compactor_client_grpc.NewCompactorClient(conn)
Expand Down Expand Up @@ -74,7 +76,7 @@ func TestGRPCGetDeleteRequests(t *testing.T) {
store.getAllResult = []DeleteRequest{{RequestID: "test-request-1", Status: StatusReceived}, {RequestID: "test-request-2", Status: StatusReceived}}
h := NewGRPCRequestHandler(store, &fakeLimits{mode: deletionmode.FilterAndDelete.String()})
grpcClient, closer := server(t, h)
defer closer()
t.Cleanup(closer)

ctx, _ := user.InjectIntoGRPCRequest(user.InjectOrgID(context.Background(), user1))
orgID, err := tenant.TenantID(ctx)
Expand All @@ -96,7 +98,7 @@ func TestGRPCGetDeleteRequests(t *testing.T) {
}
h := NewGRPCRequestHandler(store, &fakeLimits{mode: deletionmode.FilterAndDelete.String()})
grpcClient, closer := server(t, h)
defer closer()
t.Cleanup(closer)

ctx, _ := user.InjectIntoGRPCRequest(user.InjectOrgID(context.Background(), user1))
orgID, err := tenant.TenantID(ctx)
Expand Down Expand Up @@ -124,7 +126,7 @@ func TestGRPCGetDeleteRequests(t *testing.T) {
}
h := NewGRPCRequestHandler(store, &fakeLimits{mode: deletionmode.FilterAndDelete.String()})
grpcClient, closer := server(t, h)
defer closer()
t.Cleanup(closer)

ctx, _ := user.InjectIntoGRPCRequest(user.InjectOrgID(context.Background(), user1))
orgID, err := tenant.TenantID(ctx)
Expand All @@ -145,7 +147,7 @@ func TestGRPCGetDeleteRequests(t *testing.T) {
store.getAllErr = errors.New("something bad")
h := NewGRPCRequestHandler(store, &fakeLimits{mode: deletionmode.FilterAndDelete.String()})
grpcClient, closer := server(t, h)
defer closer()
t.Cleanup(closer)

ctx, _ := user.InjectIntoGRPCRequest(user.InjectOrgID(context.Background(), user1))
orgID, err := tenant.TenantID(ctx)
Expand All @@ -162,7 +164,7 @@ func TestGRPCGetDeleteRequests(t *testing.T) {
t.Run("no org id", func(t *testing.T) {
h := NewGRPCRequestHandler(&mockDeleteRequestsStore{}, &fakeLimits{mode: deletionmode.FilterAndDelete.String()})
grpcClient, closer := server(t, h)
defer closer()
t.Cleanup(closer)

_, err := grpcClient.GetDeleteRequests(context.Background(), &compactor_client_grpc.GetDeleteRequestsRequest{})
require.Error(t, err)
Expand All @@ -178,7 +180,7 @@ func TestGRPCGetCacheGenNumbers(t *testing.T) {
store.genNumber = "123"
h := NewGRPCRequestHandler(store, &fakeLimits{mode: deletionmode.FilterAndDelete.String()})
grpcClient, closer := server(t, h)
defer closer()
t.Cleanup(closer)

ctx, _ := user.InjectIntoGRPCRequest(user.InjectOrgID(context.Background(), user1))
orgID, err := tenant.TenantID(ctx)
Expand All @@ -195,7 +197,7 @@ func TestGRPCGetCacheGenNumbers(t *testing.T) {
store.getErr = errors.New("something bad")
h := NewGRPCRequestHandler(store, &fakeLimits{mode: deletionmode.FilterAndDelete.String()})
grpcClient, closer := server(t, h)
defer closer()
t.Cleanup(closer)

ctx, _ := user.InjectIntoGRPCRequest(user.InjectOrgID(context.Background(), user1))
orgID, err := tenant.TenantID(ctx)
Expand All @@ -212,7 +214,7 @@ func TestGRPCGetCacheGenNumbers(t *testing.T) {
t.Run("no org id", func(t *testing.T) {
h := NewGRPCRequestHandler(&mockDeleteRequestsStore{}, &fakeLimits{mode: deletionmode.FilterAndDelete.String()})
grpcClient, closer := server(t, h)
defer closer()
t.Cleanup(closer)

_, err := grpcClient.GetCacheGenNumbers(context.Background(), &compactor_client_grpc.GetCacheGenNumbersRequest{})
require.Error(t, err)
Expand Down