From c50f2df33bf8e015d37199606326808b02bc3a98 Mon Sep 17 00:00:00 2001 From: Christian Simon Date: Wed, 13 Apr 2022 07:56:52 +0100 Subject: [PATCH] Add WIP test --- .../series/series_index_gateway_store_test.go | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/pkg/storage/stores/series/series_index_gateway_store_test.go b/pkg/storage/stores/series/series_index_gateway_store_test.go index 4270152383d84..09e63ec0851b7 100644 --- a/pkg/storage/stores/series/series_index_gateway_store_test.go +++ b/pkg/storage/stores/series/series_index_gateway_store_test.go @@ -2,12 +2,15 @@ package series import ( "context" + "log" + "net" "testing" "github.com/prometheus/common/model" "github.com/stretchr/testify/require" "google.golang.org/grpc" + "github.com/grafana/dskit/grpcclient" "github.com/grafana/loki/pkg/storage/stores/shipper/indexgateway/indexgatewaypb" ) @@ -29,3 +32,55 @@ func Test_IndexGatewayClient(t *testing.T) { _, err := idx.GetSeries(context.Background(), "foo", model.Earliest, model.Latest) require.NoError(t, err) } + +func Test_IndexGatewayClient_Fallback(t *testing.T) { + lis, err := net.Listen("tcp", "localhost:0") + require.NoError(t, err) + s := grpc.NewServer() + + // register fake grpc service with missing methods + desc := grpc.ServiceDesc{ + ServiceName: "indexgatewaypb.IndexGateway", + HandlerType: (*indexgatewaypb.IndexGatewayServer)(nil), + Streams: []grpc.StreamDesc{ + { + StreamName: "QueryIndex", + Handler: nil, + ServerStreams: true, + }, + }, + Metadata: "pkg/storage/stores/shipper/indexgateway/indexgatewaypb/gateway.proto", + } + s.RegisterService(&desc, nil) + + go func() { + if err := s.Serve(lis); err != nil { + log.Fatalf("Failed to serve: %v", err) + } + }() + defer func() { + s.GracefulStop() + }() + + cfg := grpcclient.Config{ + MaxRecvMsgSize: 1024, + MaxSendMsgSize: 1024, + } + + dialOpts, err := cfg.DialOption(nil, nil) + require.NoError(t, err) + + conn, err := grpc.Dial(lis.Addr().String(), dialOpts...) + require.NoError(t, err) + defer conn.Close() + + idx := NewIndexGatewayClientStore( + indexgatewaypb.NewIndexGatewayClient(conn), + &IndexStore{ + chunkBatchSize: 1, + }, + ) + + _, err = idx.GetSeries(context.Background(), "foo", model.Earliest, model.Latest) + require.NoError(t, err) +}