@@ -2959,6 +2959,114 @@ func (s *mutableStateSuite) TestRetryActivity_PausedIncrementsStamp() {
29592959 s .Equal (int32 (2 ), updatedActivityInfo .Attempt )
29602960}
29612961
2962+ func (s * mutableStateSuite ) TestFlushPendingActivityEventsForCompletion () {
2963+ s .mockEventsCache .EXPECT ().PutEvent (gomock .Any (), gomock .Any ()).AnyTimes ()
2964+
2965+ tq := & taskqueuepb.TaskQueue {Name : "tq" }
2966+ retryPolicy := & commonpb.RetryPolicy {
2967+ InitialInterval : durationpb .New (time .Second ),
2968+ }
2969+
2970+ s .Run ("no_pending_activities" , func () {
2971+ s .createVersionedMutableStateWithCompletedWFT (tq )
2972+ nextBefore := s .mutableState .GetNextEventID ()
2973+ err := s .mutableState .FlushPendingActivityEventsForCompletion ()
2974+ s .NoError (err )
2975+ s .Equal (nextBefore , s .mutableState .GetNextEventID ())
2976+ })
2977+
2978+ s .Run ("pending_activity_with_transient_started_flushes_started" , func () {
2979+ s .createVersionedMutableStateWithCompletedWFT (tq )
2980+ workflowTaskCompletedEventID := s .mutableState .GetNextEventID () - 1
2981+ _ , activityInfo , err := s .mutableState .AddActivityTaskScheduledEvent (
2982+ workflowTaskCompletedEventID ,
2983+ & commandpb.ScheduleActivityTaskCommandAttributes {
2984+ ActivityId : "flush-started" ,
2985+ ActivityType : & commonpb.ActivityType {Name : "activity-type" },
2986+ TaskQueue : tq ,
2987+ RetryPolicy : retryPolicy ,
2988+ },
2989+ false ,
2990+ )
2991+ s .NoError (err )
2992+ _ , err = s .mutableState .AddActivityTaskStartedEvent (
2993+ activityInfo ,
2994+ activityInfo .ScheduledEventId ,
2995+ uuid .NewString (),
2996+ "worker" ,
2997+ nil ,
2998+ nil ,
2999+ nil ,
3000+ )
3001+ s .NoError (err )
3002+ ai , ok := s .mutableState .GetActivityInfo (activityInfo .ScheduledEventId )
3003+ s .True (ok )
3004+ s .Equal (common .TransientEventID , ai .StartedEventId )
3005+
3006+ err = s .mutableState .FlushPendingActivityEventsForCompletion ()
3007+ s .NoError (err )
3008+ ai , ok = s .mutableState .GetActivityInfo (activityInfo .ScheduledEventId )
3009+ s .True (ok )
3010+ s .NotEqual (common .TransientEventID , ai .StartedEventId , "flush should have written ActivityTaskStarted so StartedEventId is no longer transient" )
3011+ })
3012+
3013+ s .Run ("pending_activity_between_retries_flushes_started_and_failed" , func () {
3014+ s .createVersionedMutableStateWithCompletedWFT (tq )
3015+ workflowTaskCompletedEventID := s .mutableState .GetNextEventID () - 1
3016+ _ , activityInfo , err := s .mutableState .AddActivityTaskScheduledEvent (
3017+ workflowTaskCompletedEventID ,
3018+ & commandpb.ScheduleActivityTaskCommandAttributes {
3019+ ActivityId : "flush-failed" ,
3020+ ActivityType : & commonpb.ActivityType {Name : "activity-type" },
3021+ TaskQueue : tq ,
3022+ RetryPolicy : retryPolicy ,
3023+ },
3024+ false ,
3025+ )
3026+ s .NoError (err )
3027+ _ , err = s .mutableState .AddActivityTaskStartedEvent (
3028+ activityInfo ,
3029+ activityInfo .ScheduledEventId ,
3030+ uuid .NewString (),
3031+ "worker" ,
3032+ nil ,
3033+ nil ,
3034+ nil ,
3035+ )
3036+ s .NoError (err )
3037+ _ , err = s .mutableState .RetryActivity (activityInfo , & failurepb.Failure {Message : "attempt failed" })
3038+ s .NoError (err )
3039+ s .Len (s .mutableState .GetPendingActivityInfos (), 1 )
3040+
3041+ err = s .mutableState .FlushPendingActivityEventsForCompletion ()
3042+ s .NoError (err )
3043+ s .Len (s .mutableState .GetPendingActivityInfos (), 0 )
3044+ _ , ok := s .mutableState .GetActivityInfo (activityInfo .ScheduledEventId )
3045+ s .False (ok )
3046+ })
3047+
3048+ s .Run ("pending_activity_without_retry_skipped" , func () {
3049+ s .createVersionedMutableStateWithCompletedWFT (tq )
3050+ workflowTaskCompletedEventID := s .mutableState .GetNextEventID () - 1
3051+ _ , _ , err := s .mutableState .AddActivityTaskScheduledEvent (
3052+ workflowTaskCompletedEventID ,
3053+ & commandpb.ScheduleActivityTaskCommandAttributes {
3054+ ActivityId : "no-retry" ,
3055+ ActivityType : & commonpb.ActivityType {Name : "activity-type" },
3056+ TaskQueue : tq ,
3057+ },
3058+ false ,
3059+ )
3060+ s .NoError (err )
3061+ s .Len (s .mutableState .GetPendingActivityInfos (), 1 )
3062+ nextBefore := s .mutableState .GetNextEventID ()
3063+ err = s .mutableState .FlushPendingActivityEventsForCompletion ()
3064+ s .NoError (err )
3065+ s .Equal (nextBefore , s .mutableState .GetNextEventID ())
3066+ s .Len (s .mutableState .GetPendingActivityInfos (), 1 )
3067+ })
3068+ }
3069+
29623070func (s * mutableStateSuite ) TestupdateBuildIdsAndDeploymentSearchAttributes () {
29633071 versioned := func (buildId string ) * commonpb.WorkerVersionStamp {
29643072 return & commonpb.WorkerVersionStamp {BuildId : buildId , UseVersioning : true }
0 commit comments