@@ -36,6 +36,7 @@ import (
3636 commandpb "go.temporal.io/api/command/v1"
3737 commonpb "go.temporal.io/api/common/v1"
3838 enumspb "go.temporal.io/api/enums/v1"
39+ failurepb "go.temporal.io/api/failure/v1"
3940 historypb "go.temporal.io/api/history/v1"
4041 taskqueuepb "go.temporal.io/api/taskqueue/v1"
4142
@@ -105,6 +106,8 @@ func (s *mutableStateSuite) SetupTest() {
105106 // set the checksum probabilities to 100% for exercising during test
106107 s .mockConfig .MutableStateChecksumGenProbability = func (namespace string ) int { return 100 }
107108 s .mockConfig .MutableStateChecksumVerifyProbability = func (namespace string ) int { return 100 }
109+ s .mockConfig .MutableStateActivityFailureSizeLimitWarn = func (namespace string ) int { return 1 * 1024 }
110+ s .mockConfig .MutableStateActivityFailureSizeLimitError = func (namespace string ) int { return 2 * 1024 }
108111 s .mockShard .SetEventsCacheForTesting (s .mockEventsCache )
109112
110113 s .testScope = s .mockShard .Resource .MetricsScope .(tally.TestScope )
@@ -839,49 +842,41 @@ func (s *mutableStateSuite) TestReplicateActivityTaskStartedEvent() {
839842}
840843
841844func (s * mutableStateSuite ) TestTotalEntitiesCount () {
842- namespaceEntry := s .newNamespaceCacheEntry ()
843- mutableState := TestLocalMutableState (
844- s .mockShard ,
845- s .mockEventsCache ,
846- namespaceEntry ,
847- s .logger ,
848- uuid .New (),
849- )
850845 s .mockEventsCache .EXPECT ().PutEvent (gomock .Any (), gomock .Any ()).AnyTimes ()
851846
852847 // scheduling, starting & completing workflow task is omitted here
853848
854849 workflowTaskCompletedEventID := int64 (4 )
855- _ , _ , err := mutableState .AddActivityTaskScheduledEvent (
850+ _ , _ , err := s . mutableState .AddActivityTaskScheduledEvent (
856851 workflowTaskCompletedEventID ,
857852 & commandpb.ScheduleActivityTaskCommandAttributes {},
858853 false ,
859854 )
860855 s .NoError (err )
861856
862- _ , _ , err = mutableState .AddStartChildWorkflowExecutionInitiatedEvent (
857+ _ , _ , err = s . mutableState .AddStartChildWorkflowExecutionInitiatedEvent (
863858 workflowTaskCompletedEventID ,
864859 uuid .New (),
865860 & commandpb.StartChildWorkflowExecutionCommandAttributes {},
866861 namespace .ID (uuid .New ()),
867862 )
868863 s .NoError (err )
869864
870- _ , _ , err = mutableState .AddTimerStartedEvent (
865+ _ , _ , err = s . mutableState .AddTimerStartedEvent (
871866 workflowTaskCompletedEventID ,
872867 & commandpb.StartTimerCommandAttributes {},
873868 )
874869 s .NoError (err )
875870
876- _ , _ , err = mutableState .AddRequestCancelExternalWorkflowExecutionInitiatedEvent (
871+ _ , _ , err = s . mutableState .AddRequestCancelExternalWorkflowExecutionInitiatedEvent (
877872 workflowTaskCompletedEventID ,
878873 uuid .New (),
879874 & commandpb.RequestCancelExternalWorkflowExecutionCommandAttributes {},
880875 namespace .ID (uuid .New ()),
881876 )
882877 s .NoError (err )
883878
884- _ , _ , err = mutableState .AddSignalExternalWorkflowExecutionInitiatedEvent (
879+ _ , _ , err = s . mutableState .AddSignalExternalWorkflowExecutionInitiatedEvent (
885880 workflowTaskCompletedEventID ,
886881 uuid .New (),
887882 & commandpb.SignalExternalWorkflowExecutionCommandAttributes {
@@ -894,7 +889,7 @@ func (s *mutableStateSuite) TestTotalEntitiesCount() {
894889 )
895890 s .NoError (err )
896891
897- _ , err = mutableState .AddWorkflowExecutionSignaled (
892+ _ , err = s . mutableState .AddWorkflowExecutionSignaled (
898893 "signalName" ,
899894 & commonpb.Payloads {},
900895 "identity" ,
@@ -903,12 +898,12 @@ func (s *mutableStateSuite) TestTotalEntitiesCount() {
903898 s .NoError (err )
904899
905900 s .mockShard .Resource .ClusterMetadata .EXPECT ().ClusterNameForFailoverVersion (
906- namespaceEntry .IsGlobalNamespace (),
907- mutableState .GetCurrentVersion (),
901+ tests . LocalNamespaceEntry .IsGlobalNamespace (),
902+ s . mutableState .GetCurrentVersion (),
908903 ).Return (cluster .TestCurrentClusterName )
909904 s .mockShard .Resource .ClusterMetadata .EXPECT ().GetCurrentClusterName ().Return (cluster .TestCurrentClusterName )
910905
911- mutation , _ , err := mutableState .CloseTransactionAsMutation (
906+ mutation , _ , err := s . mutableState .CloseTransactionAsMutation (
912907 TransactionPolicyActive ,
913908 )
914909 s .NoError (err )
@@ -982,3 +977,62 @@ func (s *mutableStateSuite) TestSpeculativeWorkflowTaskNotPersisted() {
982977 })
983978 }
984979}
980+
981+ func (s * mutableStateSuite ) TestRetryActivity_TruncateRetryableFailure () {
982+ s .mockEventsCache .EXPECT ().PutEvent (gomock .Any (), gomock .Any ()).AnyTimes ()
983+
984+ // scheduling, starting & completing workflow task is omitted here
985+
986+ workflowTaskCompletedEventID := int64 (4 )
987+ _ , activityInfo , err := s .mutableState .AddActivityTaskScheduledEvent (
988+ workflowTaskCompletedEventID ,
989+ & commandpb.ScheduleActivityTaskCommandAttributes {
990+ ActivityId : "5" ,
991+ ActivityType : & commonpb.ActivityType {Name : "activity-type" },
992+ TaskQueue : & taskqueuepb.TaskQueue {Name : "task-queue" },
993+ RetryPolicy : & commonpb.RetryPolicy {
994+ InitialInterval : timestamp .DurationFromSeconds (1 ),
995+ },
996+ },
997+ false ,
998+ )
999+ s .NoError (err )
1000+
1001+ _ , err = s .mutableState .AddActivityTaskStartedEvent (
1002+ activityInfo ,
1003+ activityInfo .ScheduledEventId ,
1004+ uuid .New (),
1005+ "worker-identity" ,
1006+ )
1007+ s .NoError (err )
1008+
1009+ failureSizeErrorLimit := s .mockConfig .MutableStateActivityFailureSizeLimitError (
1010+ s .mutableState .namespaceEntry .Name ().String (),
1011+ )
1012+
1013+ activityFailure := & failurepb.Failure {
1014+ Message : "activity failure with large details" ,
1015+ Source : "application" ,
1016+ FailureInfo : & failurepb.Failure_ApplicationFailureInfo {ApplicationFailureInfo : & failurepb.ApplicationFailureInfo {
1017+ Type : "application-failure-type" ,
1018+ NonRetryable : false ,
1019+ Details : & commonpb.Payloads {
1020+ Payloads : []* commonpb.Payload {
1021+ {
1022+ Data : make ([]byte , failureSizeErrorLimit * 2 ),
1023+ },
1024+ },
1025+ },
1026+ }},
1027+ }
1028+ s .Greater (activityFailure .Size (), failureSizeErrorLimit )
1029+
1030+ retryState , err := s .mutableState .RetryActivity (activityInfo , activityFailure )
1031+ s .NoError (err )
1032+ s .Equal (enumspb .RETRY_STATE_IN_PROGRESS , retryState )
1033+
1034+ activityInfo , ok := s .mutableState .GetActivityInfo (activityInfo .ScheduledEventId )
1035+ s .True (ok )
1036+ s .LessOrEqual (activityInfo .RetryLastFailure .Size (), failureSizeErrorLimit )
1037+ s .Equal (activityFailure .GetMessage (), activityInfo .RetryLastFailure .Cause .GetMessage ())
1038+ }
0 commit comments