@@ -709,7 +709,7 @@ func (s *resetorSuite) TestResetWorkflowExecution_NoReplication() {
709709 for _ , e := range be .Events {
710710 eid ++
711711 if e .GetEventId () != eid {
712- s .Fail (fmt .Sprintf ("inconintous eventID: %v, %v" , eid , e .GetEventId ()))
712+ s .Fail (fmt .Sprintf ("non-continuous eventID: %v, %v" , eid , e .GetEventId ()))
713713 }
714714 e .EventTime = & eventTime
715715 }
@@ -1403,7 +1403,7 @@ func (s *resetorSuite) TestResetWorkflowExecution_NoReplication_WithRequestCance
14031403 for _ , e := range be .Events {
14041404 eid ++
14051405 if e .GetEventId () != eid {
1406- s .Fail (fmt .Sprintf ("inconintous eventID: %v, %v" , eid , e .GetEventId ()))
1406+ s .Fail (fmt .Sprintf ("non-continuous eventID: %v, %v" , eid , e .GetEventId ()))
14071407 }
14081408 e .EventTime = & eventTime
14091409 }
@@ -1998,7 +1998,7 @@ func (s *resetorSuite) TestResetWorkflowExecution_Replication_WithTerminatingCur
19981998 for _ , e := range be .Events {
19991999 eid ++
20002000 if e .GetEventId () != eid {
2001- s .Fail (fmt .Sprintf ("inconintous eventID: %v, %v" , eid , e .GetEventId ()))
2001+ s .Fail (fmt .Sprintf ("non-continuous eventID: %v, %v" , eid , e .GetEventId ()))
20022002 }
20032003 e .EventTime = & eventTime
20042004 }
@@ -2703,7 +2703,7 @@ func (s *resetorSuite) TestResetWorkflowExecution_Replication_NotActive() {
27032703 for _ , e := range be .Events {
27042704 eid ++
27052705 if e .GetEventId () != eid {
2706- s .Fail (fmt .Sprintf ("inconintous eventID: %v, %v" , eid , e .GetEventId ()))
2706+ s .Fail (fmt .Sprintf ("non-continuous eventID: %v, %v" , eid , e .GetEventId ()))
27072707 }
27082708 e .EventTime = & eventTime
27092709 }
@@ -3304,7 +3304,7 @@ func (s *resetorSuite) TestResetWorkflowExecution_Replication_NoTerminatingCurre
33043304 for _ , e := range be .Events {
33053305 eid ++
33063306 if e .GetEventId () != eid {
3307- s .Fail (fmt .Sprintf ("inconintous eventID: %v, %v" , eid , e .GetEventId ()))
3307+ s .Fail (fmt .Sprintf ("non-continuous eventID: %v, %v" , eid , e .GetEventId ()))
33083308 }
33093309 e .EventTime = & eventTime
33103310 }
@@ -3923,7 +3923,7 @@ func (s *resetorSuite) TestApplyReset() {
39233923 for _ , e := range be .Events {
39243924 eid ++
39253925 if e .GetEventId () != eid {
3926- s .Fail (fmt .Sprintf ("inconintous eventID: %v, %v" , eid , e .GetEventId ()))
3926+ s .Fail (fmt .Sprintf ("non-continuous eventID: %v, %v" , eid , e .GetEventId ()))
39273927 }
39283928 e .EventTime = & eventTime
39293929 }
@@ -4319,7 +4319,7 @@ func (s *resetorSuite) TestResetWorkflowExecution_WithoutRunID() {
43194319 for _ , e := range be .Events {
43204320 eid ++
43214321 if e .GetEventId () != eid {
4322- s .Fail (fmt .Sprintf ("inconintous eventID: %v, %v" , eid , e .GetEventId ()))
4322+ s .Fail (fmt .Sprintf ("non-continuous eventID: %v, %v" , eid , e .GetEventId ()))
43234323 }
43244324 e .EventTime = & eventTime
43254325 }
@@ -4371,3 +4371,165 @@ func (s *resetorSuite) TestResetWorkflowExecution_WithoutRunID() {
43714371 s .Nil (err )
43724372 s .NotNil (response .RunId )
43734373}
4374+
4375+ func (s * resetorSuite ) TestResetWorkflowExecution_NoCompletedTasks () {
4376+ testNamespaceEntry := cache .NewLocalNamespaceCacheEntryForTest (
4377+ & persistenceblobs.NamespaceInfo {Id : testNamespaceID }, & persistenceblobs.NamespaceConfig {Retention : timestamp .DurationFromDays (1 )}, "" , nil ,
4378+ )
4379+ s .mockNamespaceCache .EXPECT ().GetNamespaceByID (gomock .Any ()).Return (testNamespaceEntry , nil ).AnyTimes ()
4380+ s .mockNamespaceCache .EXPECT ().GetNamespace (gomock .Any ()).Return (testNamespaceEntry , nil ).AnyTimes ()
4381+
4382+ namespaceID := testNamespaceID
4383+
4384+ request := & historyservice.ResetWorkflowExecutionRequest {NamespaceId : namespaceID , ResetRequest : & workflowservice.ResetWorkflowExecutionRequest {}}
4385+
4386+ wid := "wId"
4387+ wfType := "wfType"
4388+ taskQueueName := "taskQueue"
4389+ forkRunID := uuid .New ().String ()
4390+ currRunID := uuid .New ().String ()
4391+
4392+ we := commonpb.WorkflowExecution {
4393+ WorkflowId : wid ,
4394+ RunId : forkRunID ,
4395+ }
4396+
4397+ request .ResetRequest = & workflowservice.ResetWorkflowExecutionRequest {
4398+ Namespace : "testNamespace" ,
4399+ WorkflowExecution : & we ,
4400+ Reason : "test reset" ,
4401+ WorkflowTaskFinishEventId : 3 ,
4402+ RequestId : uuid .New ().String (),
4403+ }
4404+
4405+ forkBranchToken := []byte ("forkBranchToken" )
4406+ taskQueue := & taskqueuepb.TaskQueue {
4407+ Name : taskQueueName ,
4408+ }
4409+ // Prepare history event sequence.
4410+ readHistoryResponse := & persistence.ReadHistoryBranchByBatchResponse {
4411+ NextPageToken : nil ,
4412+ Size : 1000 ,
4413+ LastFirstEventID : int64 (3 ),
4414+ History : []* historypb.History {
4415+ {
4416+ Events : []* historypb.HistoryEvent {
4417+ {
4418+ EventId : 1 ,
4419+ Version : common .EmptyVersion ,
4420+ EventType : enumspb .EVENT_TYPE_WORKFLOW_EXECUTION_STARTED ,
4421+ Attributes : & historypb.HistoryEvent_WorkflowExecutionStartedEventAttributes {WorkflowExecutionStartedEventAttributes : & historypb.WorkflowExecutionStartedEventAttributes {
4422+ WorkflowType : & commonpb.WorkflowType {
4423+ Name : wfType ,
4424+ },
4425+ TaskQueue : taskQueue ,
4426+ Input : payloads .EncodeString ("testInput" ),
4427+ WorkflowExecutionTimeout : timestamp .DurationPtr (100 * time .Second ),
4428+ WorkflowRunTimeout : timestamp .DurationPtr (50 * time .Second ),
4429+ WorkflowTaskTimeout : timestamp .DurationPtr (200 * time .Second ),
4430+ }},
4431+ },
4432+ {
4433+ EventId : 2 ,
4434+ Version : common .EmptyVersion ,
4435+ EventType : enumspb .EVENT_TYPE_WORKFLOW_TASK_SCHEDULED ,
4436+ Attributes : & historypb.HistoryEvent_WorkflowTaskScheduledEventAttributes {WorkflowTaskScheduledEventAttributes : & historypb.WorkflowTaskScheduledEventAttributes {
4437+ TaskQueue : taskQueue ,
4438+ StartToCloseTimeout : timestamp .DurationPtr (100 * time .Second ),
4439+ }},
4440+ },
4441+ },
4442+ },
4443+ {
4444+ Events : []* historypb.HistoryEvent {
4445+ {
4446+ EventId : 3 ,
4447+ Version : common .EmptyVersion ,
4448+ EventType : enumspb .EVENT_TYPE_WORKFLOW_EXECUTION_TIMED_OUT ,
4449+ Attributes : & historypb.HistoryEvent_WorkflowTaskTimedOutEventAttributes {WorkflowTaskTimedOutEventAttributes : & historypb.WorkflowTaskTimedOutEventAttributes {}},
4450+ },
4451+ },
4452+ },
4453+ },
4454+ }
4455+
4456+ eid := int64 (0 )
4457+ eventTime := time .Unix (0 , 1000 ).UTC ()
4458+ for _ , be := range readHistoryResponse .History {
4459+ for _ , e := range be .Events {
4460+ eid ++
4461+ if e .GetEventId () != eid {
4462+ s .Fail (fmt .Sprintf ("non-continuous eventID: %v, %v" , eid , e .GetEventId ()))
4463+ }
4464+ e .EventTime = & eventTime
4465+ }
4466+ }
4467+
4468+ // Mock calls.
4469+ s .mockExecutionMgr .On ("GetWorkflowExecution" , & persistence.GetWorkflowExecutionRequest {
4470+ NamespaceID : namespaceID ,
4471+ Execution : commonpb.WorkflowExecution {
4472+ WorkflowId : wid ,
4473+ RunId : forkRunID ,
4474+ },
4475+ }).Return (& persistence.GetWorkflowExecutionResponse {State : & persistence.WorkflowMutableState {
4476+ ExecutionInfo : & persistence.WorkflowExecutionInfo {
4477+ NamespaceID : namespaceID ,
4478+ WorkflowID : wid ,
4479+ WorkflowTypeName : wfType ,
4480+ TaskQueue : taskQueueName ,
4481+ RunID : forkRunID ,
4482+ BranchToken : forkBranchToken ,
4483+ NextEventID : 4 ,
4484+ WorkflowTaskVersion : common .EmptyVersion ,
4485+ WorkflowTaskScheduleID : common .EmptyEventID ,
4486+ WorkflowTaskStartedID : common .EmptyEventID ,
4487+ State : enumsspb .WORKFLOW_EXECUTION_STATE_CREATED ,
4488+ },
4489+ ExecutionStats : & persistenceblobs.ExecutionStats {},
4490+ }}, nil ).Once ()
4491+ s .mockExecutionMgr .On ("GetCurrentExecution" , mock .Anything ).Return (& persistence.GetCurrentExecutionResponse {
4492+ RunID : currRunID ,
4493+ }, nil ).Once ()
4494+ s .mockExecutionMgr .On ("GetWorkflowExecution" , & persistence.GetWorkflowExecutionRequest {
4495+ NamespaceID : namespaceID ,
4496+ Execution : commonpb.WorkflowExecution {
4497+ WorkflowId : wid ,
4498+ RunId : currRunID ,
4499+ },
4500+ }).Return (& persistence.GetWorkflowExecutionResponse {State : & persistence.WorkflowMutableState {
4501+ ExecutionInfo : & persistence.WorkflowExecutionInfo {
4502+ NamespaceID : namespaceID ,
4503+ WorkflowID : wid ,
4504+ WorkflowTypeName : wfType ,
4505+ TaskQueue : taskQueueName ,
4506+ RunID : currRunID ,
4507+ NextEventID : common .FirstEventID ,
4508+ WorkflowTaskVersion : common .EmptyVersion ,
4509+ WorkflowTaskScheduleID : common .EmptyEventID ,
4510+ WorkflowTaskStartedID : common .EmptyEventID ,
4511+ State : enumsspb .WORKFLOW_EXECUTION_STATE_CREATED ,
4512+ },
4513+ ExecutionStats : & persistenceblobs.ExecutionStats {},
4514+ }}, nil ).Once ()
4515+ s .mockHistoryV2Mgr .On ("ReadHistoryBranchByBatch" , & persistence.ReadHistoryBranchRequest {
4516+ BranchToken : forkBranchToken ,
4517+ MinEventID : common .FirstEventID ,
4518+ MaxEventID : int64 (4 ),
4519+ PageSize : defaultHistoryPageSize ,
4520+ NextPageToken : nil ,
4521+ ShardID : & s .shardID ,
4522+ }).Return (readHistoryResponse , nil ).Once ()
4523+ s .mockHistoryV2Mgr .On ("ForkHistoryBranch" , mock .Anything ).Return (& persistence.ForkHistoryBranchResponse {
4524+ NewBranchToken : []byte ("newBranch" ),
4525+ }, nil ).Once ()
4526+ s .mockHistoryV2Mgr .On ("AppendHistoryNodes" , mock .Anything ).Return (& persistence.AppendHistoryNodesResponse {
4527+ Size : 200 ,
4528+ }, nil ).Times (2 )
4529+ s .mockExecutionMgr .On ("ResetWorkflowExecution" , mock .Anything ).Return (nil ).Once ()
4530+
4531+ // Perform a reset and make sure there is no error.
4532+ response , err := s .historyEngine .ResetWorkflowExecution (context .Background (), request )
4533+ s .Nil (err )
4534+ s .NotNil (response .RunId )
4535+ }
0 commit comments