Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
feedmeapples committed May 11, 2023
1 parent 51530d3 commit ec97af2
Showing 1 changed file with 46 additions and 49 deletions.
95 changes: 46 additions & 49 deletions tests/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,52 @@ func (s *e2eSuite) TestWorkflowTerminate_Batch() {
}, 10*time.Second, time.Second, "timed out awaiting for workflows termination")
}

func (s *e2eSuite) TestWorkflowDelete_Batch() {
s.T().Parallel()

testserver, app, _ := s.setUpTestEnvironment()
defer func() {
_ = testserver.Stop()
}()

w := s.newWorker(testserver, testTq, func(r worker.Registry) {
r.RegisterWorkflow(awaitsignal.Workflow)
})
defer w.Stop()

c := testserver.Client()

ids := []string{"1", "2", "3"}

for _, id := range ids {
_, err := c.ExecuteWorkflow(
context.Background(),
sdkclient.StartWorkflowOptions{ID: id, TaskQueue: testTq},
awaitsignal.Workflow,
)
s.NoError(err)
}

err := app.Run([]string{"", "workflow", "delete", "--query", "WorkflowId = '1' OR WorkflowId = '2'", "--reason", "test", "--yes", "--namespace", testNamespace})
s.NoError(err)

awaitTaskQueuePoller(s, c, testTq)
awaitBatchJob(s, c, testNamespace)

s.Eventually(func() bool {
wfs, err := c.ListWorkflow(context.Background(), &workflowservice.ListWorkflowExecutionsRequest{
Namespace: testNamespace,
})
s.NoError(err)

if len(wfs.GetExecutions()) == 1 && wfs.GetExecutions()[0].GetExecution().GetWorkflowId() == "3" {
return true
}

return false
}, 10*time.Second, time.Second, "timed out awaiting for workflows termination")
}

// awaitTaskQueuePoller used mostly for more explicit failure message
func awaitTaskQueuePoller(s *e2eSuite, c sdkclient.Client, taskqueue string) {
s.Eventually(func() bool {
Expand Down Expand Up @@ -335,55 +381,6 @@ func awaitBatchJob(s *e2eSuite, c sdkclient.Client, ns string) {
}, 10*time.Second, time.Second, "cancellation batch job timed out")
}

func (s *e2eSuite) TestWorkflowDelete_Batch() {
s.T().Parallel()

testserver, app, _ := s.setUpTestEnvironment()
defer func() {
_ = testserver.Stop()
}()

c := testserver.Client()

ids := []string{"1", "2", "3"}

for _, id := range ids {
_, err := c.ExecuteWorkflow(
context.Background(),
sdkclient.StartWorkflowOptions{ID: id, TaskQueue: testTq},
"non-existing-workflow-type",
)
s.NoError(err)
}

err := app.Run([]string{"", "workflow", "delete", "--query", "WorkflowId = '1' OR WorkflowId = '2'", "--reason", "test", "--yes", "--namespace", testNamespace})
s.NoError(err)

// verify the deletion is complete
time.Sleep(1 * time.Second)
resp, err := c.WorkflowService().ListBatchOperations(context.Background(),
&workflowservice.ListBatchOperationsRequest{Namespace: testNamespace})
s.NoError(err)
s.Equal(1, len(resp.OperationInfo))
deleteJob, err := c.WorkflowService().DescribeBatchOperation(context.Background(),
&workflowservice.DescribeBatchOperationRequest{
JobId: resp.OperationInfo[0].JobId,
Namespace: testNamespace,
})
s.NoError(err)
s.Equal(enums.BATCH_OPERATION_STATE_COMPLETED, deleteJob.State)

_, err = c.DescribeWorkflowExecution(context.Background(), "1", "")
s.Error(err)

_, err = c.DescribeWorkflowExecution(context.Background(), "2", "")
s.Error(err)

w3, err := c.DescribeWorkflowExecution(context.Background(), "3", "")
s.NoError(err)
s.Equal(enums.WORKFLOW_EXECUTION_STATUS_RUNNING, w3.WorkflowExecutionInfo.Status)
}

func checkForEventType(events sdkclient.HistoryEventIterator, eventType enums.EventType) bool {
for events.HasNext() {
event, err := events.Next()
Expand Down

0 comments on commit ec97af2

Please sign in to comment.