Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit 3a475b4

Browse files
3vilhamstermrombout
authored andcommitted
Add unit tests for SideEffect (cadence-workflow#1390)
1 parent bd67843 commit 3a475b4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

internal/internal_event_handlers_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,31 @@ func TestWorkflowExecutionEventHandler_ProcessEvent_no_error_events(t *testing.T
695695
}
696696
}
697697

698+
func TestSideEffect(t *testing.T) {
699+
t.Run("replay", func(t *testing.T) {
700+
weh := testWorkflowExecutionEventHandler(t, newRegistry())
701+
weh.workflowEnvironmentImpl.isReplay = true
702+
weh.sideEffectResult[weh.counterID] = []byte("test")
703+
weh.SideEffect(func() ([]byte, error) {
704+
t.Error("side effect should not be called during replay")
705+
t.Failed()
706+
return nil, assert.AnError
707+
}, func(result []byte, err error) {
708+
assert.NoError(t, err)
709+
assert.Equal(t, "test", string(result))
710+
})
711+
})
712+
t.Run("success", func(t *testing.T) {
713+
weh := testWorkflowExecutionEventHandler(t, newRegistry())
714+
weh.SideEffect(func() ([]byte, error) {
715+
return []byte("test"), nil
716+
}, func(result []byte, err error) {
717+
assert.NoError(t, err)
718+
assert.Equal(t, "test", string(result))
719+
})
720+
})
721+
}
722+
698723
func testWorkflowExecutionEventHandler(t *testing.T, registry *registry) *workflowExecutionEventHandlerImpl {
699724
return newWorkflowExecutionEventHandler(
700725
testWorkflowInfo,

0 commit comments

Comments
 (0)