Skip to content

Commit 4c008c7

Browse files
committed
improve tests
Signed-off-by: Fabian Martinez <[email protected]>
1 parent 1bb5ccb commit 4c008c7

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

tests/worker_test.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ func Test_TryProcessSingleOrchestrationWorkItem_BasicFlow(t *testing.T) {
7474
}, 1*time.Second, 100*time.Millisecond)
7575

7676
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)
7782
}
7883

7984
func Test_TryProcessSingleOrchestrationWorkItem_Idempotency(t *testing.T) {
@@ -106,12 +111,20 @@ func Test_TryProcessSingleOrchestrationWorkItem_Idempotency(t *testing.T) {
106111
be := mocks.NewBackend(t)
107112
ex := mocks.NewExecutor(t)
108113

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+
109124
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()
111125
be.EXPECT().AbandonOrchestrationWorkItem(anyContext, wi).Return(nil).Once()
112126

113127
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()
115128
be.EXPECT().CompleteOrchestrationWorkItem(anyContext, wi).RunAndReturn(func(ctx context.Context, owi *backend.OrchestrationWorkItem) error {
116129
completed.Store(true)
117130
return nil
@@ -131,6 +144,12 @@ func Test_TryProcessSingleOrchestrationWorkItem_Idempotency(t *testing.T) {
131144
}, 2*time.Second, 100*time.Millisecond)
132145

133146
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)
134153
}
135154

136155
func Test_TryProcessSingleOrchestrationWorkItem_ExecutionStartedAndCompleted(t *testing.T) {
@@ -213,6 +232,12 @@ func Test_TryProcessSingleOrchestrationWorkItem_ExecutionStartedAndCompleted(t *
213232
}, 1*time.Second, 100*time.Millisecond)
214233

215234
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)
216241
}
217242

218243
func Test_TaskWorker(t *testing.T) {

0 commit comments

Comments
 (0)