Skip to content

Commit

Permalink
Add unit tests for SideEffect (#1390)
Browse files Browse the repository at this point in the history
  • Loading branch information
3vilhamster authored Nov 6, 2024
1 parent 275c434 commit 17b9b1a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/internal_event_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,31 @@ func TestWorkflowExecutionEventHandler_ProcessEvent_no_error_events(t *testing.T
}
}

func TestSideEffect(t *testing.T) {
t.Run("replay", func(t *testing.T) {
weh := testWorkflowExecutionEventHandler(t, newRegistry())
weh.workflowEnvironmentImpl.isReplay = true
weh.sideEffectResult[weh.counterID] = []byte("test")
weh.SideEffect(func() ([]byte, error) {
t.Error("side effect should not be called during replay")
t.Failed()
return nil, assert.AnError
}, func(result []byte, err error) {
assert.NoError(t, err)
assert.Equal(t, "test", string(result))
})
})
t.Run("success", func(t *testing.T) {
weh := testWorkflowExecutionEventHandler(t, newRegistry())
weh.SideEffect(func() ([]byte, error) {
return []byte("test"), nil
}, func(result []byte, err error) {
assert.NoError(t, err)
assert.Equal(t, "test", string(result))
})
})
}

func testWorkflowExecutionEventHandler(t *testing.T, registry *registry) *workflowExecutionEventHandlerImpl {
return newWorkflowExecutionEventHandler(
testWorkflowInfo,
Expand Down

0 comments on commit 17b9b1a

Please sign in to comment.