From 17b9b1a0c2ea9c4e26cf918345b45ff09bbcd9df Mon Sep 17 00:00:00 2001 From: Ilya Ozherelyev Date: Wed, 6 Nov 2024 13:44:11 +0100 Subject: [PATCH] Add unit tests for SideEffect (#1390) --- internal/internal_event_handlers_test.go | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/internal/internal_event_handlers_test.go b/internal/internal_event_handlers_test.go index 6af1e2494..6acc7ce10 100644 --- a/internal/internal_event_handlers_test.go +++ b/internal/internal_event_handlers_test.go @@ -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,