698
699
// TestDelete test
701
>
openRows := 10
702
>
closedRows := 5
703
>
testNamespaceUUID := namespace.ID(uuid.NewString())
704
>
closeTime := time.Now().UTC()
705
>
startTime := closeTime.Add(-5 * time.Second)
706
>
executionTime := closeTime.Add(-4 * time.Second)
707
>
var startRequests []*manager.RecordWorkflowExecutionStartedRequest
708
>
for range openRows {
709
>
startReq := s.createOpenWorkflowRecord(
710
>
testNamespaceUUID,
711
>
uuid.NewString(),
712
>
"visibility-workflow",
713
>
startTime,
714
>
executionTime,
715
>
"test-queue",
716
>
)
717
>
startRequests = append(startRequests, startReq)
718
>
}
719
721
>
s.createClosedWorkflowRecord(
722
>
startRequests[i],
723
>
closeTime,
724
>
enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
725
>
)
726
>
}
727
728
// ListClosedWorkflowExecutions
730
>
NamespaceID: testNamespaceUUID,
731
>
PageSize: 10,
732
>
Query: fmt.Sprintf("%s >= '%s' AND %s <= '%s' AND %s != '%s'",
733
>
sadefs.CloseTime,
734
>
startTime.Format(time.RFC3339Nano),
735
>
sadefs.CloseTime,
736
>
closeTime.Format(time.RFC3339Nano),
737
>
sadefs.ExecutionStatus,
738
>
enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING,
739
>
),
740
>
})
741
>
s.NoError(err3)
742
>
s.Len(resp.Executions, closedRows)
743
>
744
>
// Delete closed workflow
745
>
for _, row := range resp.Executions {
746
>
err4 := s.VisibilityMgr.DeleteWorkflowExecution(s.ctx, &manager.VisibilityDeleteWorkflowExecutionRequest{
747
>
NamespaceID: testNamespaceUUID,
748
>
WorkflowID: row.GetExecution().GetWorkflowId(),
749
>
RunID: row.GetExecution().GetRunId(),
750
>
})
751
>
s.NoError(err4)
752
>
}
753
754
// ListClosedWorkflowExecutions
756
>
NamespaceID: testNamespaceUUID,
757
>
PageSize: 10,
758
>
Query: fmt.Sprintf("%s >= '%s' AND %s <= '%s' AND %s != '%s'",
759
>
sadefs.CloseTime,
760
>
startTime.Format(time.RFC3339Nano),
761
>
sadefs.CloseTime,
762
>
closeTime.Format(time.RFC3339Nano),
763
>
sadefs.ExecutionStatus,
764
>
enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING,
765
>
),
766
>
})
767
>
s.NoError(err5)
768
>
s.Empty(resp.Executions)
769
>
770
>
// ListOpenWorkflowExecutions
771
>
resp, err6 := s.VisibilityMgr.ListWorkflowExecutions(s.ctx, &manager.ListWorkflowExecutionsRequestV2{
772
>
NamespaceID: testNamespaceUUID,
773
>
Query: fmt.Sprintf("%s >= '%s' AND %s <= '%s'AND %s = '%s'",
774
>
sadefs.StartTime,
775
>
startTime.Format(time.RFC3339Nano),
776
>
sadefs.StartTime,
777
>
closeTime.Format(time.RFC3339Nano),
778
>
sadefs.ExecutionStatus,
779
>
enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING,
780
>
),
781
>
PageSize: 10,
782
>
})
783
>
s.NoError(err6)
784
>
s.Len(resp.Executions, openRows-closedRows)
785
>
// Delete open workflow
786
>
for _, row := range resp.Executions {
787
>
err7 := s.VisibilityMgr.DeleteWorkflowExecution(s.ctx, &manager.VisibilityDeleteWorkflowExecutionRequest{
788
>
NamespaceID: testNamespaceUUID,
789
>
WorkflowID: row.GetExecution().GetWorkflowId(),
790
>
RunID: row.GetExecution().GetRunId(),
791
>
})
792
>
s.NoError(err7)
793
>
}
794
>
resp, err8 := s.VisibilityMgr.ListWorkflowExecutions(s.ctx, &manager.ListWorkflowExecutionsRequestV2{
795
>
NamespaceID: testNamespaceUUID,
796
>
Query: fmt.Sprintf("%s >= '%s' AND %s <= '%s'",
797
>
sadefs.StartTime,
798
>
startTime.Format(time.RFC3339Nano),
799
>
sadefs.StartTime,
800
>
closeTime.Format(time.RFC3339Nano),
801
>
),
802
>
PageSize: 10,
803
>
})
804
>
s.NoError(err8)
805
>
s.Empty(resp.Executions)
806
}
807