Skip to content

Commit

Permalink
Fix List OR query (cadence-workflow#1923)
Browse files Browse the repository at this point in the history
* Fix List OR query

* Fix manual test

* Add integration test
  • Loading branch information
vancexu authored May 30, 2019
1 parent 80fc5c2 commit a113370
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 25 deletions.
10 changes: 5 additions & 5 deletions common/persistence/elasticsearch/esVisibilityStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,13 @@ func addDomainToQuery(dsl *fastjson.Value, domainID string) {
addMustQuery(dsl, domainQueryString)
}

// addMustQuery is wrapping bool query with new bool query with must,
// reason not making a flat bool query is to ensure "should (or)" query works correctly in query context.
func addMustQuery(dsl *fastjson.Value, queryString string) {
valOfTopQuery := dsl.Get("query")
valOfBool := dsl.Get("query", "bool")
if valOfMust := valOfBool.Get(dslFieldMust); valOfMust == nil {
valOfBool.Set(dslFieldMust, fastjson.MustParse(fmt.Sprintf("[%s]", queryString)))
} else {
valOfMust.SetArrayItem(len(valOfMust.GetArray()), fastjson.MustParse(queryString))
}
newValOfBool := fmt.Sprintf(`{"must":[%s,{"bool":%s}]}`, queryString, valOfBool.String())
valOfTopQuery.Set("bool", fastjson.MustParse(newValOfBool))
}

func shouldSearchAfter(token *esVisibilityPageToken) bool {
Expand Down
40 changes: 20 additions & 20 deletions common/persistence/elasticsearch/esVisibilityStore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ func (s *ESVisibilitySuite) TestGetESQueryDSL() {
dsl, isOpen, err := getESQueryDSL(request, token)
s.Nil(err)
s.False(isOpen)
s.Equal(`{"query":{"bool":{"must":[{"match_all":{}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"match_all":{}}]}}]}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)

request.Query = "invaild query"
dsl, isOpen, err = getESQueryDSL(request, token)
Expand All @@ -674,49 +674,49 @@ func (s *ESVisibilitySuite) TestGetESQueryDSL() {
dsl, isOpen, err = getESQueryDSL(request, token)
s.Nil(err)
s.False(isOpen)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}}]}}]}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)

request.Query = `WorkflowID = 'wid' or WorkflowID = 'another-wid'`
dsl, isOpen, err = getESQueryDSL(request, token)
s.Nil(err)
s.False(isOpen)
s.Equal(`{"query":{"bool":{"should":[{"match_phrase":{"WorkflowID":{"query":"wid"}}},{"match_phrase":{"WorkflowID":{"query":"another-wid"}}}],"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"should":[{"match_phrase":{"WorkflowID":{"query":"wid"}}},{"match_phrase":{"WorkflowID":{"query":"another-wid"}}}]}}]}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)

request.Query = `WorkflowID = 'wid' order by StartTime desc`
dsl, isOpen, err = getESQueryDSL(request, token)
s.Nil(err)
s.False(isOpen)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}},"from":0,"size":10,"sort":[{"StartTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}}]}}]}},"from":0,"size":10,"sort":[{"StartTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)

request.Query = `WorkflowID = 'wid' and CloseTime = missing`
dsl, isOpen, err = getESQueryDSL(request, token)
s.Nil(err)
s.True(isOpen)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}],"must_not":{"exists":{"field":"CloseTime"}}}},"from":0,"size":10,"sort":[{"StartTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}}],"must_not":{"exists":{"field":"CloseTime"}}}}]}},"from":0,"size":10,"sort":[{"StartTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)

request.Query = `CloseTime = missing order by CloseTime desc`
dsl, isOpen, err = getESQueryDSL(request, token)
s.Nil(err)
s.True(isOpen)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}],"must_not":{"exists":{"field":"CloseTime"}}}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[],"must_not":{"exists":{"field":"CloseTime"}}}}]}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)

request.Query = `WorkflowID = 'wid' and StartTime > "2018-06-07T15:04:05+00:00"`
dsl, isOpen, err = getESQueryDSL(request, token)
s.Nil(err)
s.False(isOpen)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}},{"range":{"StartTime":{"gt":"1528383845000000000"}}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}},{"range":{"StartTime":{"gt":"1528383845000000000"}}}]}}]}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)

request.Query = `ExecutionTime < 1000`
dsl, isOpen, err = getESQueryDSL(request, token)
s.Nil(err)
s.False(isOpen)
s.Equal(`{"query":{"bool":{"must":[{"range":{"ExecutionTime":{"lt":"1000"}}},{"range":{"ExecutionTime":{"gt":"0"}}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"range":{"ExecutionTime":{"gt":"0"}}},{"bool":{"must":[{"range":{"ExecutionTime":{"lt":"1000"}}}]}}]}}]}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)

request.Query = `ExecutionTime < 1000 or ExecutionTime > 2000`
dsl, isOpen, err = getESQueryDSL(request, token)
s.Nil(err)
s.False(isOpen)
s.Equal(`{"query":{"bool":{"should":[{"range":{"ExecutionTime":{"lt":"1000"}}},{"range":{"ExecutionTime":{"gt":"2000"}}}],"must":[{"range":{"ExecutionTime":{"gt":"0"}}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"range":{"ExecutionTime":{"gt":"0"}}},{"bool":{"should":[{"range":{"ExecutionTime":{"lt":"1000"}}},{"range":{"ExecutionTime":{"gt":"2000"}}}]}}]}}]}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}]}`, dsl)

request.Query = `ExecutionTime < "unable to parse"`
_, _, err = getESQueryDSL(request, token)
Expand All @@ -730,7 +730,7 @@ func (s *ESVisibilitySuite) TestGetESQueryDSL() {
dsl, isOpen, err = getESQueryDSL(request, token)
s.Nil(err)
s.False(isOpen)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}],"search_after":[1,"a"]}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}}]}}]}},"from":0,"size":10,"sort":[{"CloseTime":"desc"},{"WorkflowID":"desc"}],"search_after":[1,"a"]}`, dsl)
}

func (s *ESVisibilitySuite) TestGetESQueryDSLForScan() {
Expand All @@ -744,25 +744,25 @@ func (s *ESVisibilitySuite) TestGetESQueryDSLForScan() {
dsl, isOpen, err := getESQueryDSLForScan(request, token)
s.Nil(err)
s.False(isOpen)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}},"from":0,"size":10}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}}]}}]}},"from":0,"size":10}`, dsl)

request.Query = `WorkflowID = 'wid'`
dsl, isOpen, err = getESQueryDSLForScan(request, token)
s.Nil(err)
s.False(isOpen)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}},"from":0,"size":10}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}}]}}]}},"from":0,"size":10}`, dsl)

request.Query = `CloseTime = missing and (ExecutionTime >= "2019-08-27T15:04:05+00:00" or StartTime <= "2018-06-07T15:04:05+00:00")`
dsl, isOpen, err = getESQueryDSLForScan(request, token)
s.Nil(err)
s.True(isOpen)
s.Equal(`{"query":{"bool":{"must":[{"bool":{"should":[{"range":{"ExecutionTime":{"from":"1566918245000000000"}}},{"range":{"StartTime":{"to":"1528383845000000000"}}}]}},{"range":{"ExecutionTime":{"gt":"0"}}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}],"must_not":{"exists":{"field":"CloseTime"}}}},"from":0,"size":10}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"range":{"ExecutionTime":{"gt":"0"}}},{"bool":{"must":[{"bool":{"should":[{"range":{"ExecutionTime":{"from":"1566918245000000000"}}},{"range":{"StartTime":{"to":"1528383845000000000"}}}]}}],"must_not":{"exists":{"field":"CloseTime"}}}}]}}]}},"from":0,"size":10}`, dsl)

request.Query = `ExecutionTime < 1000 and ExecutionTime > 500`
dsl, isOpen, err = getESQueryDSLForScan(request, token)
s.Nil(err)
s.False(isOpen)
s.Equal(`{"query":{"bool":{"must":[{"range":{"ExecutionTime":{"lt":"1000"}}},{"range":{"ExecutionTime":{"gt":"500"}}},{"range":{"ExecutionTime":{"gt":"0"}}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}},"from":0,"size":10}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"range":{"ExecutionTime":{"gt":"0"}}},{"bool":{"must":[{"range":{"ExecutionTime":{"lt":"1000"}}},{"range":{"ExecutionTime":{"gt":"500"}}}]}}]}}]}},"from":0,"size":10}`, dsl)
}

func (s *ESVisibilitySuite) TestGetESQueryDSLForCount() {
Expand All @@ -773,22 +773,22 @@ func (s *ESVisibilitySuite) TestGetESQueryDSLForCount() {
// empty query
dsl, err := getESQueryDSLForCount(request)
s.Nil(err)
s.Equal(`{"query":{"bool":{"must":[{"match_all":{}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}}}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"match_all":{}}]}}]}}}`, dsl)

request.Query = `WorkflowID = 'wid' order by StartTime desc`
dsl, err = getESQueryDSLForCount(request)
s.Nil(err)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}}}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"match_phrase":{"WorkflowID":{"query":"wid"}}}]}}]}}}`, dsl)

request.Query = `CloseTime < "2018-06-07T15:04:05+07:00" and StartTime > "2018-05-04T16:00:00+07:00" and ExecutionTime >= "2018-05-05T16:00:00+07:00"`
dsl, err = getESQueryDSLForCount(request)
s.Nil(err)
s.Equal(`{"query":{"bool":{"must":[{"range":{"CloseTime":{"lt":"1528358645000000000"}}},{"range":{"StartTime":{"gt":"1525424400000000000"}}},{"range":{"ExecutionTime":{"from":"1525510800000000000"}}},{"range":{"ExecutionTime":{"gt":"0"}}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}}}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"range":{"ExecutionTime":{"gt":"0"}}},{"bool":{"must":[{"range":{"CloseTime":{"lt":"1528358645000000000"}}},{"range":{"StartTime":{"gt":"1525424400000000000"}}},{"range":{"ExecutionTime":{"from":"1525510800000000000"}}}]}}]}}]}}}`, dsl)

request.Query = `ExecutionTime > 1000`
request.Query = `ExecutionTime < 1000`
dsl, err = getESQueryDSLForCount(request)
s.Nil(err)
s.Equal(`{"query":{"bool":{"must":[{"range":{"ExecutionTime":{"gt":"1000"}}},{"range":{"ExecutionTime":{"gt":"0"}}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}}}`, dsl)
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"range":{"ExecutionTime":{"gt":"0"}}},{"bool":{"must":[{"range":{"ExecutionTime":{"lt":"1000"}}}]}}]}}]}}}`, dsl)
}

func (s *ESVisibilitySuite) TestAddDomainToQuery() {
Expand All @@ -799,7 +799,7 @@ func (s *ESVisibilitySuite) TestAddDomainToQuery() {

dsl = fastjson.MustParse(`{"query":{"bool":{"must":[{"match_all":{}}]}}}`)
addDomainToQuery(dsl, testDomainID)
s.Equal(`{"query":{"bool":{"must":[{"match_all":{}},{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}}]}}}`, dsl.String())
s.Equal(`{"query":{"bool":{"must":[{"match_phrase":{"DomainID":{"query":"bfd5c907-f899-4baf-a7b2-2ab85e623ebd"}}},{"bool":{"must":[{"match_all":{}}]}}]}}}`, dsl.String())
}

func (s *ESVisibilitySuite) TestListWorkflowExecutions() {
Expand Down
105 changes: 105 additions & 0 deletions host/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,111 @@ func (s *elasticsearchIntegrationSuite) TestListWorkflow_SearchAfter() {
s.testListWorkflowHelper(numOfWorkflows, pageSize, request, id, wt, false)
}

func (s *elasticsearchIntegrationSuite) TestListWorkflow_OrQuery() {
id := "es-integration-list-workflow-or-query-test"
wt := "es-integration-list-workflow-or-query-test-type"
tl := "es-integration-list-workflow-or-query-test-tasklist"
request := s.createStartWorkflowExecutionRequest(id, wt, tl)

// start 3 workflows
key := definition.CustomIntField
attrValBytes, _ := json.Marshal(1)
searchAttr := &workflow.SearchAttributes{
IndexedFields: map[string][]byte{
key: attrValBytes,
},
}
request.SearchAttributes = searchAttr
we1, err := s.engine.StartWorkflowExecution(createContext(), request)
s.Nil(err)

request.RequestId = common.StringPtr(uuid.New())
request.WorkflowId = common.StringPtr(id + "-2")
attrValBytes, _ = json.Marshal(2)
searchAttr.IndexedFields[key] = attrValBytes
we2, err := s.engine.StartWorkflowExecution(createContext(), request)
s.Nil(err)

request.RequestId = common.StringPtr(uuid.New())
request.WorkflowId = common.StringPtr(id + "-3")
attrValBytes, _ = json.Marshal(3)
searchAttr.IndexedFields[key] = attrValBytes
we3, err := s.engine.StartWorkflowExecution(createContext(), request)
s.Nil(err)

// query 1 workflow with search attr
query1 := fmt.Sprintf(`CustomIntField = %d`, 1)
var openExecution *workflow.WorkflowExecutionInfo
listRequest := &workflow.ListWorkflowExecutionsRequest{
Domain: common.StringPtr(s.domainName),
PageSize: common.Int32Ptr(100),
Query: common.StringPtr(query1),
}
for i := 0; i < numOfRetry; i++ {
resp, err := s.engine.ListWorkflowExecutions(createContext(), listRequest)
s.Nil(err)
if len(resp.GetExecutions()) == 1 {
openExecution = resp.GetExecutions()[0]
break
}
time.Sleep(waitTimeInMs * time.Millisecond)
}
s.NotNil(openExecution)
s.Equal(we1.GetRunId(), openExecution.GetExecution().GetRunId())
s.True(openExecution.GetExecutionTime() >= openExecution.GetStartTime())
searchValBytes := openExecution.SearchAttributes.GetIndexedFields()[key]
var searchVal int
json.Unmarshal(searchValBytes, &searchVal)
s.Equal(1, searchVal)

// query with or clause
query2 := fmt.Sprintf(`CustomIntField = %d or CustomIntField = %d`, 1, 2)
listRequest.Query = common.StringPtr(query2)
var openExecutions []*workflow.WorkflowExecutionInfo
for i := 0; i < numOfRetry; i++ {
resp, err := s.engine.ListWorkflowExecutions(createContext(), listRequest)
s.Nil(err)
if len(resp.GetExecutions()) == 2 {
openExecutions = resp.GetExecutions()
break
}
time.Sleep(waitTimeInMs * time.Millisecond)
}
s.Equal(2, len(openExecutions))
e1 := openExecutions[0]
e2 := openExecutions[1]
if e1.GetExecution().GetRunId() != we1.GetRunId() {
// results are sorted by [CloseTime,RunID] desc, so find the correct mapping first
e1, e2 = e2, e1
}
s.Equal(we1.GetRunId(), e1.GetExecution().GetRunId())
s.Equal(we2.GetRunId(), e2.GetExecution().GetRunId())
searchValBytes = e2.SearchAttributes.GetIndexedFields()[key]
json.Unmarshal(searchValBytes, &searchVal)
s.Equal(2, searchVal)

// query for open
query3 := fmt.Sprintf(`(CustomIntField = %d or CustomIntField = %d) and CloseTime = missing`, 2, 3)
listRequest.Query = common.StringPtr(query3)
for i := 0; i < numOfRetry; i++ {
resp, err := s.engine.ListWorkflowExecutions(createContext(), listRequest)
s.Nil(err)
if len(resp.GetExecutions()) == 2 {
openExecutions = resp.GetExecutions()
break
}
time.Sleep(waitTimeInMs * time.Millisecond)
}
s.Equal(2, len(openExecutions))
e1 = openExecutions[0]
e2 = openExecutions[1]
s.Equal(we3.GetRunId(), e1.GetExecution().GetRunId())
s.Equal(we2.GetRunId(), e2.GetExecution().GetRunId())
searchValBytes = e1.SearchAttributes.GetIndexedFields()[key]
json.Unmarshal(searchValBytes, &searchVal)
s.Equal(3, searchVal)
}

func (s *elasticsearchIntegrationSuite) testListWorkflowHelper(numOfWorkflows, pageSize int,
startRequest *workflow.StartWorkflowExecutionRequest, wid, wType string, isScan bool) {

Expand Down

0 comments on commit a113370

Please sign in to comment.