@@ -49,7 +49,7 @@ const (
49
49
)
50
50
51
51
func Test__identifyIssues (t * testing.T ) {
52
- dwtest := testDiagnosticWorkflow (t )
52
+ dwtest := testDiagnosticWorkflow (t , testWorkflowExecutionHistoryResponseWithMultipleIssues () )
53
53
actMetadata := failure.FailureIssuesMetadata {
54
54
Identity : "localhost" ,
55
55
ActivityType : "test-activity" ,
@@ -58,39 +58,42 @@ func Test__identifyIssues(t *testing.T) {
58
58
}
59
59
actMetadataInBytes , err := json .Marshal (actMetadata )
60
60
require .NoError (t , err )
61
- retryMetadata := retry.RetryMetadata {
62
- EventID : 2 ,
63
- RetryPolicy : & types.RetryPolicy {
64
- InitialIntervalInSeconds : 1 ,
65
- MaximumAttempts : 1 ,
66
- },
67
- }
68
- retryMetadataInBytes , err := json .Marshal (retryMetadata )
69
- require .NoError (t , err )
70
61
expectedResult := []invariant.InvariantCheckResult {
71
62
{
72
63
IssueID : 0 ,
73
64
InvariantType : failure .ActivityFailed .String (),
74
65
Reason : failure .GenericError .String (),
75
66
Metadata : actMetadataInBytes ,
76
67
},
77
- {
78
- IssueID : 0 ,
68
+ }
69
+ for i := 0 ; i < _maxIssuesPerInvariant ; i ++ {
70
+ retryMetadata := retry.RetryMetadata {
71
+ EventID : int64 (i ),
72
+ RetryPolicy : & types.RetryPolicy {
73
+ InitialIntervalInSeconds : 1 ,
74
+ MaximumAttempts : 1 ,
75
+ },
76
+ }
77
+ retryMetadataInBytes , err := json .Marshal (retryMetadata )
78
+ require .NoError (t , err )
79
+ expectedResult = append (expectedResult , invariant.InvariantCheckResult {
80
+ IssueID : i ,
79
81
InvariantType : retry .ActivityRetryIssue .String (),
80
82
Reason : retry .RetryPolicyValidationMaxAttempts .String (),
81
83
Metadata : retryMetadataInBytes ,
82
- },
84
+ })
83
85
}
84
86
result , err := dwtest .identifyIssues (context .Background (), identifyIssuesParams {Execution : & types.WorkflowExecution {
85
87
WorkflowID : "123" ,
86
88
RunID : "abc" ,
87
89
}})
88
90
require .NoError (t , err )
91
+ require .Equal (t , _maxIssuesPerInvariant + 1 , len (result )) // retry invariant returns 10 issues (capped) , failure invariant returns 1 issue
89
92
require .Equal (t , expectedResult , result )
90
93
}
91
94
92
95
func Test__rootCauseIssues (t * testing.T ) {
93
- dwtest := testDiagnosticWorkflow (t )
96
+ dwtest := testDiagnosticWorkflow (t , testWorkflowExecutionHistoryResponse () )
94
97
actMetadata := failure.FailureIssuesMetadata {
95
98
Identity : "localhost" ,
96
99
ActivityScheduledID : 1 ,
@@ -120,7 +123,7 @@ func Test__rootCauseIssues(t *testing.T) {
120
123
121
124
func Test__emit (t * testing.T ) {
122
125
ctrl := gomock .NewController (t )
123
- dwtest := testDiagnosticWorkflow (t )
126
+ dwtest := testDiagnosticWorkflow (t , testWorkflowExecutionHistoryResponse () )
124
127
mockClient := messaging .NewMockClient (ctrl )
125
128
mockProducer := messaging .NewMockProducer (ctrl )
126
129
mockProducer .EXPECT ().Publish (gomock .Any (), gomock .Any ()).Return (nil )
@@ -129,12 +132,12 @@ func Test__emit(t *testing.T) {
129
132
require .NoError (t , err )
130
133
}
131
134
132
- func testDiagnosticWorkflow (t * testing.T ) * dw {
135
+ func testDiagnosticWorkflow (t * testing.T , history * types. GetWorkflowExecutionHistoryResponse ) * dw {
133
136
ctrl := gomock .NewController (t )
134
137
mockClientBean := client .NewMockBean (ctrl )
135
138
mockFrontendClient := frontend .NewMockClient (ctrl )
136
139
mockClientBean .EXPECT ().GetFrontendClient ().Return (mockFrontendClient ).AnyTimes ()
137
- mockFrontendClient .EXPECT ().GetWorkflowExecutionHistory (gomock .Any (), gomock .Any ()).Return (testWorkflowExecutionHistoryResponse () , nil ).AnyTimes ()
140
+ mockFrontendClient .EXPECT ().GetWorkflowExecutionHistory (gomock .Any (), gomock .Any ()).Return (history , nil ).AnyTimes ()
138
141
return & dw {
139
142
clientBean : mockClientBean ,
140
143
invariants : []invariant.Invariant {failure .NewInvariant (), retry .NewInvariant ()},
@@ -193,6 +196,49 @@ func testWorkflowExecutionHistoryResponse() *types.GetWorkflowExecutionHistoryRe
193
196
}
194
197
}
195
198
199
+ func testWorkflowExecutionHistoryResponseWithMultipleIssues () * types.GetWorkflowExecutionHistoryResponse {
200
+ testResponse := & types.GetWorkflowExecutionHistoryResponse {History : & types.History {
201
+ Events : []* types.HistoryEvent {
202
+ {
203
+ ID : 1 ,
204
+ Timestamp : common .Int64Ptr (testTimeStamp ),
205
+ WorkflowExecutionStartedEventAttributes : & types.WorkflowExecutionStartedEventAttributes {
206
+ ExecutionStartToCloseTimeoutSeconds : common .Int32Ptr (workflowTimeoutSecond ),
207
+ },
208
+ },
209
+ },
210
+ }}
211
+ for i := 0 ; i <= 20 ; i ++ {
212
+ testResponse .History .Events = append (testResponse .History .Events , & types.HistoryEvent {
213
+ ID : int64 (i ),
214
+ ActivityTaskScheduledEventAttributes : & types.ActivityTaskScheduledEventAttributes {
215
+ ActivityID : string (rune (i )),
216
+ ActivityType : & types.ActivityType {Name : "test-activity" },
217
+ StartToCloseTimeoutSeconds : common .Int32Ptr (int32 (10 )),
218
+ HeartbeatTimeoutSeconds : common .Int32Ptr (int32 (5 )),
219
+ RetryPolicy : & types.RetryPolicy {
220
+ InitialIntervalInSeconds : 1 ,
221
+ MaximumAttempts : 1 ,
222
+ },
223
+ },
224
+ })
225
+
226
+ }
227
+ testResponse .History .Events = append (testResponse .History .Events , & types.HistoryEvent {
228
+ ID : 4 ,
229
+ Timestamp : common .Int64Ptr (testTimeStamp ),
230
+ ActivityTaskFailedEventAttributes : & types.ActivityTaskFailedEventAttributes {
231
+ Reason : common .StringPtr ("cadenceInternal:Generic" ),
232
+ Details : []byte ("test-activity-failure" ),
233
+ Identity : "localhost" ,
234
+ ScheduledEventID : 2 ,
235
+ StartedEventID : 3 ,
236
+ },
237
+ })
238
+
239
+ return testResponse
240
+ }
241
+
196
242
func Test__identifyIssuesWithPaginatedHistory (t * testing.T ) {
197
243
ctrl := gomock .NewController (t )
198
244
mockClientBean := client .NewMockBean (ctrl )
0 commit comments