@@ -74,6 +74,11 @@ func Test_TryProcessSingleOrchestrationWorkItem_BasicFlow(t *testing.T) {
74
74
}, 1 * time .Second , 100 * time .Millisecond )
75
75
76
76
worker .StopAndDrain ()
77
+
78
+ t .Logf ("state.NewEvents: %v" , state .NewEvents )
79
+ require .Len (t , state .NewEvents , 2 )
80
+ require .True (t , state .NewEvents [0 ].GetOrchestratorStarted () != nil )
81
+ require .True (t , state .NewEvents [1 ].GetExecutionStarted () != nil )
77
82
}
78
83
79
84
func Test_TryProcessSingleOrchestrationWorkItem_Idempotency (t * testing.T ) {
@@ -106,12 +111,20 @@ func Test_TryProcessSingleOrchestrationWorkItem_Idempotency(t *testing.T) {
106
111
be := mocks .NewBackend (t )
107
112
ex := mocks .NewExecutor (t )
108
113
114
+ callNumber := 0
115
+ ex .EXPECT ().ExecuteOrchestrator (anyContext , wi .InstanceID , wi .State .OldEvents , mock .Anything ).RunAndReturn (func (ctx context.Context , iid api.InstanceID , oldEvents []* protos.HistoryEvent , newEvents []* protos.HistoryEvent ) (* protos.OrchestratorResponse , error ) {
116
+ callNumber ++
117
+ logger .Debugf ("execute orchestrator called %d times" , callNumber )
118
+ if callNumber == 1 {
119
+ return nil , errors .New ("dummy error" )
120
+ }
121
+ return & protos.OrchestratorResponse {}, nil
122
+ }).Times (2 )
123
+
109
124
be .EXPECT ().NextOrchestrationWorkItem (anyContext ).Return (wi , nil ).Once ()
110
- ex .EXPECT ().ExecuteOrchestrator (anyContext , wi .InstanceID , wi .State .OldEvents , mock .Anything ).Return (nil , errors .New ("dummy error" )).Once ()
111
125
be .EXPECT ().AbandonOrchestrationWorkItem (anyContext , wi ).Return (nil ).Once ()
112
126
113
127
be .EXPECT ().NextOrchestrationWorkItem (anyContext ).Return (wi , nil ).Once ()
114
- ex .EXPECT ().ExecuteOrchestrator (anyContext , wi .InstanceID , wi .State .OldEvents , mock .Anything ).Return (& protos.OrchestratorResponse {}, nil ).Once ()
115
128
be .EXPECT ().CompleteOrchestrationWorkItem (anyContext , wi ).RunAndReturn (func (ctx context.Context , owi * backend.OrchestrationWorkItem ) error {
116
129
completed .Store (true )
117
130
return nil
@@ -131,6 +144,12 @@ func Test_TryProcessSingleOrchestrationWorkItem_Idempotency(t *testing.T) {
131
144
}, 2 * time .Second , 100 * time .Millisecond )
132
145
133
146
worker .StopAndDrain ()
147
+
148
+ t .Logf ("state.NewEvents: %v" , wi .State .NewEvents )
149
+ require .Len (t , wi .State .NewEvents , 3 )
150
+ require .True (t , wi .State .NewEvents [0 ].GetOrchestratorStarted () != nil )
151
+ require .True (t , wi .State .NewEvents [1 ].GetExecutionStarted () != nil )
152
+ require .True (t , wi .State .NewEvents [2 ].GetOrchestratorStarted () != nil )
134
153
}
135
154
136
155
func Test_TryProcessSingleOrchestrationWorkItem_ExecutionStartedAndCompleted (t * testing.T ) {
@@ -213,6 +232,12 @@ func Test_TryProcessSingleOrchestrationWorkItem_ExecutionStartedAndCompleted(t *
213
232
}, 1 * time .Second , 100 * time .Millisecond )
214
233
215
234
worker .StopAndDrain ()
235
+
236
+ t .Logf ("state.NewEvents: %v" , state .NewEvents )
237
+ require .Len (t , state .NewEvents , 3 )
238
+ require .True (t , state .NewEvents [0 ].GetOrchestratorStarted () != nil )
239
+ require .True (t , state .NewEvents [1 ].GetExecutionStarted () != nil )
240
+ require .True (t , state .NewEvents [2 ].GetExecutionCompleted () != nil )
216
241
}
217
242
218
243
func Test_TaskWorker (t * testing.T ) {
0 commit comments