Skip to content

Commit

Permalink
Add Timeout tests
Browse files Browse the repository at this point in the history
  • Loading branch information
povilasv committed Mar 19, 2019
1 parent ffc61f6 commit c230d23
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
1 change: 0 additions & 1 deletion pkg/store/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ func (s *ProxyStore) Series(r *storepb.SeriesRequest, srv storepb.Store_SeriesSe
return err
}
respSender.send(storepb.NewWarnSeriesResponse(err))

continue
}

Expand Down
83 changes: 81 additions & 2 deletions pkg/store/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,88 @@ func TestProxyStore_Series(t *testing.T) {
},
expectedErr: errors.New("fetch series for [name:\"ext\" value:\"1\" ] test: error!"),
},
{
title: "partial response disabled one thanos query is slow to respond",
storeAPIs: []Client{
&testClient{
StoreClient: &mockedStoreAPI{
RespSeries: []*storepb.SeriesResponse{
storepb.NewWarnSeriesResponse(errors.New("warning")),
storeSeriesResponse(t, labels.FromStrings("a", "b"), []sample{{1, 1}, {2, 2}, {3, 3}}),
},
RespDuration: 10 * time.Second,
},
labels: []storepb.Label{{Name: "ext", Value: "1"}},
minTime: 1,
maxTime: 300,
},
&testClient{
StoreClient: &mockedStoreAPI{
RespSeries: []*storepb.SeriesResponse{
storepb.NewWarnSeriesResponse(errors.New("warning")),
storeSeriesResponse(t, labels.FromStrings("a", "b"), []sample{{1, 1}, {2, 2}, {3, 3}}),
},
},
labels: []storepb.Label{{Name: "ext", Value: "1"}},
minTime: 1,
maxTime: 300,
},
},
req: &storepb.SeriesRequest{
MinTime: 1,
MaxTime: 300,
Matchers: []storepb.LabelMatcher{{Name: "ext", Value: "1", Type: storepb.LabelMatcher_EQ}},
PartialResponseDisabled: true,
},
expectedErr: errors.New("test: failed to receive any data in 4s from test: context deadline exceeded"),
},
{
title: "partial response enabled one thanos query is slow to respond",
storeAPIs: []Client{
&testClient{
StoreClient: &mockedStoreAPI{
RespSeries: []*storepb.SeriesResponse{
storepb.NewWarnSeriesResponse(errors.New("warning")),
storeSeriesResponse(t, labels.FromStrings("a", "b"), []sample{{1, 1}, {2, 2}, {3, 3}}),
},
},
labels: []storepb.Label{{Name: "ext", Value: "1"}},
minTime: 1,
maxTime: 300,
},
&testClient{
StoreClient: &mockedStoreAPI{
RespSeries: []*storepb.SeriesResponse{
storepb.NewWarnSeriesResponse(errors.New("warning")),
storeSeriesResponse(t, labels.FromStrings("b", "c"), []sample{{1, 1}, {2, 2}, {3, 3}}),
},
RespDuration: 10 * time.Second,
},
labels: []storepb.Label{{Name: "ext", Value: "1"}},
minTime: 1,
maxTime: 300,
},
},
req: &storepb.SeriesRequest{
MinTime: 1,
MaxTime: 300,
Matchers: []storepb.LabelMatcher{{Name: "ext", Value: "1", Type: storepb.LabelMatcher_EQ}},
},
expectedSeries: []rawSeries{
{
lset: []storepb.Label{{Name: "a", Value: "b"}},
samples: []sample{{1, 1}, {2, 2}, {3, 3}},
},
},
expectedWarningsLen: 2,
},
} {
if ok := t.Run(tc.title, func(t *testing.T) {
q := NewProxyStore(nil, prometheus.NewRegistry(),
func() []Client { return tc.storeAPIs },
component.Query,
tc.selectorLabels,
10*time.Second,
4*time.Second,
)

s := newStoreSeriesServer(context.Background())
Expand Down Expand Up @@ -708,6 +783,7 @@ type mockedStoreAPI struct {
RespSeries []*storepb.SeriesResponse
RespLabelValues *storepb.LabelValuesResponse
RespError error
RespDuration time.Duration

LastSeriesReq *storepb.SeriesRequest
LastLabelValuesReq *storepb.LabelValuesRequest
Expand All @@ -720,7 +796,7 @@ func (s *mockedStoreAPI) Info(ctx context.Context, req *storepb.InfoRequest, _ .
func (s *mockedStoreAPI) Series(ctx context.Context, req *storepb.SeriesRequest, _ ...grpc.CallOption) (storepb.Store_SeriesClient, error) {
s.LastSeriesReq = req

return &StoreSeriesClient{ctx: ctx, respSet: s.RespSeries}, s.RespError
return &StoreSeriesClient{ctx: ctx, respSet: s.RespSeries, respDur: s.RespDuration}, s.RespError
}

func (s *mockedStoreAPI) LabelNames(ctx context.Context, req *storepb.LabelNamesRequest, _ ...grpc.CallOption) (*storepb.LabelNamesResponse, error) {
Expand All @@ -740,9 +816,12 @@ type StoreSeriesClient struct {
ctx context.Context
i int
respSet []*storepb.SeriesResponse
respDur time.Duration
}

func (c *StoreSeriesClient) Recv() (*storepb.SeriesResponse, error) {
time.Sleep(c.respDur)

if c.i >= len(c.respSet) {
return nil, io.EOF
}
Expand Down

0 comments on commit c230d23

Please sign in to comment.