Skip to content

Commit

Permalink
Add WIP test
Browse files Browse the repository at this point in the history
  • Loading branch information
simonswine committed Apr 13, 2022
1 parent a0118e0 commit c50f2df
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pkg/storage/stores/series/series_index_gateway_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}

0 comments on commit c50f2df

Please sign in to comment.