Skip to content

Commit f865f35

Browse files
committed
ING-1174: Allow time for index to build in test case
1 parent 9cbbbd4 commit f865f35

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

gateway/dataimpl/server_v1/errorhandler.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,17 @@ func (e ErrorHandler) NewOnlyBucketOrScopeSetStatus(baseErr error, indexName str
488488
return st
489489
}
490490

491+
func (e ErrorHandler) NewSearchIndexNotReadyStatus(baseErr error, indexName string) *status.Status {
492+
st := status.New(codes.Unavailable, "Search index is still being built, try again later.")
493+
st = e.tryAttachStatusDetails(st, &epb.ResourceInfo{
494+
ResourceType: "searchindex",
495+
ResourceName: indexName,
496+
Description: "",
497+
})
498+
st = e.tryAttachExtraContext(st, baseErr)
499+
return st
500+
}
501+
491502
func (e ErrorHandler) NewIncorrectSearchSourceTypeStatus(baseErr error, indexName string, sourceType *string) *status.Status {
492503
var sT string
493504
if sourceType != nil {

gateway/dataimpl/server_v1/searchadminserver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ func (s *SearchIndexAdminServer) AnalyzeDocument(ctx context.Context, in *admin_
391391
return nil, s.errorHandler.NewSearchIndexNameEmptyStatus(err).Err()
392392
} else if errors.Is(err, cbsearchx.ErrOnlyBucketOrScopeSet) {
393393
return nil, s.errorHandler.NewOnlyBucketOrScopeSetStatus(err, in.Name).Err()
394+
} else if errors.Is(err, cbsearchx.ErrNoIndexPartitionsFound) {
395+
return nil, s.errorHandler.NewSearchIndexNotReadyStatus(err, in.Name).Err()
394396
}
395397
return nil, s.errorHandler.NewGenericStatus(err).Err()
396398
}

gateway/test/search_mgmt_test.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,14 +1078,13 @@ func (s *GatewayOpsTestSuite) TestAnalyzeDocument() {
10781078
}
10791079

10801080
analyzeTests := []analyzeTest{
1081-
// TODO - ING-1174
1082-
// {
1083-
// description: "Basic",
1084-
// modifyDefault: func(def *admin_search_v1.AnalyzeDocumentRequest) *admin_search_v1.AnalyzeDocumentRequest {
1085-
// return def
1086-
// },
1087-
// expect: codes.OK,
1088-
// },
1081+
{
1082+
description: "Basic",
1083+
modifyDefault: func(def *admin_search_v1.AnalyzeDocumentRequest) *admin_search_v1.AnalyzeDocumentRequest {
1084+
return def
1085+
},
1086+
expect: codes.OK,
1087+
},
10891088
{
10901089
description: "IndexNotFound",
10911090
modifyDefault: func(def *admin_search_v1.AnalyzeDocumentRequest) *admin_search_v1.AnalyzeDocumentRequest {
@@ -1108,6 +1107,8 @@ func (s *GatewayOpsTestSuite) TestAnalyzeDocument() {
11081107

11091108
for i := range analyzeTests {
11101109
t := analyzeTests[i]
1110+
ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
1111+
defer cancel()
11111112
s.Run(t.description, func() {
11121113
defaultAnalyzeRequest := admin_search_v1.AnalyzeDocumentRequest{
11131114
Name: indexName,
@@ -1121,13 +1122,23 @@ func (s *GatewayOpsTestSuite) TestAnalyzeDocument() {
11211122
creds = *t.creds
11221123
}
11231124

1124-
resp, err := searchAdminClient.AnalyzeDocument(ctx, req, grpc.PerRPCCredentials(creds))
11251125
if t.expect == codes.OK {
1126-
require.NoError(s.T(), err)
1127-
requireRpcSuccess(s.T(), resp, err)
1126+
require.Eventually(s.T(), func() bool {
1127+
_, err := searchAdminClient.AnalyzeDocument(ctx, req, grpc.PerRPCCredentials(creds))
1128+
1129+
if err != nil {
1130+
assertRpcStatus(s.T(), err, codes.Unavailable)
1131+
assertRpcErrorDetails(s.T(), err, func(d *epb.ResourceInfo) {
1132+
assert.Equal(s.T(), "searchindex", d.ResourceType)
1133+
})
1134+
}
1135+
1136+
return err == nil
1137+
}, time.Second*90, time.Second*5)
11281138
return
11291139
}
11301140

1141+
_, err := searchAdminClient.AnalyzeDocument(ctx, req, grpc.PerRPCCredentials(creds))
11311142
assertRpcStatus(s.T(), err, t.expect)
11321143
assertRpcErrorDetails(s.T(), err, func(d *epb.ResourceInfo) {
11331144
assert.Equal(s.T(), t.resourceDetails, d.ResourceType)

0 commit comments

Comments
 (0)