Skip to content

Commit

Permalink
Fix flaky test (cadence-workflow#1785)
Browse files Browse the repository at this point in the history
  • Loading branch information
vancexu authored May 3, 2019
1 parent a17d8ba commit b9cf721
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions host/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ import (
"github.com/uber/cadence/common"
)

const (
numOfRetry = 50
waitTimeInMs = 400
)

type elasticsearchIntegrationSuite struct {
// override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test,
// not merely log an error
Expand Down Expand Up @@ -101,7 +106,7 @@ func (s *elasticsearchIntegrationSuite) TestListOpenWorkflow() {
startFilter := &workflow.StartTimeFilter{}
startFilter.EarliestTime = common.Int64Ptr(startTime)
var openExecution *workflow.WorkflowExecutionInfo
for i := 0; i < 20; i++ {
for i := 0; i < numOfRetry; i++ {
startFilter.LatestTime = common.Int64Ptr(time.Now().UnixNano())
resp, err := s.engine.ListOpenWorkflowExecutions(createContext(), &workflow.ListOpenWorkflowExecutionsRequest{
Domain: common.StringPtr(s.domainName),
Expand All @@ -116,7 +121,7 @@ func (s *elasticsearchIntegrationSuite) TestListOpenWorkflow() {
openExecution = resp.GetExecutions()[0]
break
}
time.Sleep(200 * time.Millisecond)
time.Sleep(waitTimeInMs * time.Millisecond)
}
s.NotNil(openExecution)
s.Equal(we.GetRunId(), openExecution.GetExecution().GetRunId())
Expand Down Expand Up @@ -226,7 +231,7 @@ func (s *elasticsearchIntegrationSuite) testListWorkflowHelper(numOfWorkflows, p
Query: common.StringPtr(fmt.Sprintf(`WorkflowType = '%s' and CloseTime = missing`, wType)),
}
// test first page
for i := 0; i < 20; i++ {
for i := 0; i < numOfRetry; i++ {
var resp *workflow.ListWorkflowExecutionsResponse
var err error

Expand All @@ -241,7 +246,7 @@ func (s *elasticsearchIntegrationSuite) testListWorkflowHelper(numOfWorkflows, p
nextPageToken = resp.NextPageToken
break
}
time.Sleep(400 * time.Millisecond)
time.Sleep(waitTimeInMs * time.Millisecond)
}
s.NotNil(openExecutions)
s.NotNil(nextPageToken)
Expand All @@ -250,7 +255,7 @@ func (s *elasticsearchIntegrationSuite) testListWorkflowHelper(numOfWorkflows, p
// test last page
listRequest.NextPageToken = nextPageToken
inIf := false
for i := 0; i < 20; i++ {
for i := 0; i < numOfRetry; i++ {
var resp *workflow.ListWorkflowExecutionsResponse
var err error

Expand All @@ -266,7 +271,7 @@ func (s *elasticsearchIntegrationSuite) testListWorkflowHelper(numOfWorkflows, p
nextPageToken = resp.NextPageToken
break
}
time.Sleep(400 * time.Millisecond)
time.Sleep(waitTimeInMs * time.Millisecond)
}
s.True(inIf)
s.NotNil(openExecutions)
Expand All @@ -283,7 +288,7 @@ func (s *elasticsearchIntegrationSuite) testHelperForReadOnce(request *workflow.
PageSize: common.Int32Ptr(100),
Query: common.StringPtr(fmt.Sprintf(`WorkflowID = "%s"`, request.GetWorkflowId())),
}
for i := 0; i < 20; i++ {
for i := 0; i < numOfRetry; i++ {
var resp *workflow.ListWorkflowExecutionsResponse
var err error

Expand All @@ -298,7 +303,7 @@ func (s *elasticsearchIntegrationSuite) testHelperForReadOnce(request *workflow.
openExecution = resp.GetExecutions()[0]
break
}
time.Sleep(200 * time.Millisecond)
time.Sleep(waitTimeInMs * time.Millisecond)
}
s.NotNil(openExecution)
s.Equal(we.GetRunId(), openExecution.GetExecution().GetRunId())
Expand Down Expand Up @@ -391,13 +396,13 @@ func (s *elasticsearchIntegrationSuite) TestCountWorkflow() {
Query: common.StringPtr(fmt.Sprintf(`WorkflowID = "%s"`, request.GetWorkflowId())),
}
var resp *workflow.CountWorkflowExecutionsResponse
for i := 0; i < 20; i++ {
for i := 0; i < numOfRetry; i++ {
resp, err = s.engine.CountWorkflowExecutions(createContext(), countRequest)
s.Nil(err)
if resp.GetCount() == int64(1) {
break
}
time.Sleep(200 * time.Millisecond)
time.Sleep(waitTimeInMs * time.Millisecond)
}
s.Equal(int64(1), resp.GetCount())
}
Expand Down

0 comments on commit b9cf721

Please sign in to comment.