From eaa93b1ad4231fc79a40e2647c1e0adf01c79431 Mon Sep 17 00:00:00 2001 From: Ilya Ozherelyev Date: Fri, 31 May 2024 14:38:22 +0200 Subject: [PATCH] Add more tests to execution manager (#6074) --- common/persistence/execution_manager_test.go | 148 +++++++++++++++++++ common/persistence/versionHistory.go | 2 +- 2 files changed, 149 insertions(+), 1 deletion(-) diff --git a/common/persistence/execution_manager_test.go b/common/persistence/execution_manager_test.go index c22dff4e38f..8f541f7d3fa 100644 --- a/common/persistence/execution_manager_test.go +++ b/common/persistence/execution_manager_test.go @@ -875,6 +875,154 @@ func TestDeserializeChildExecutionInfos(t *testing.T) { } } +func TestListConcreteExecutions(t *testing.T) { + request := &ListConcreteExecutionsRequest{ + PageSize: 10, + PageToken: []byte("next"), + } + + internalResponse := &InternalListConcreteExecutionsResponse{ + Executions: []*InternalListConcreteExecutionsEntity{ + { + ExecutionInfo: sampleInternalWorkflowExecutionInfo(), + VersionHistories: sampleEventData(), + }, + }, + NextPageToken: []byte("next"), + } + + testCases := []struct { + name string + prepareMocks func(*MockExecutionStore, *MockPayloadSerializer) + checkRes func(*testing.T, *ListConcreteExecutionsResponse, error) + }{ + { + name: "success", + prepareMocks: func(mockedStore *MockExecutionStore, mockedSerializer *MockPayloadSerializer) { + mockedStore.EXPECT().ListConcreteExecutions(gomock.Any(), request).Return(internalResponse, nil) + + mockedSerializer.EXPECT().DeserializeEvent(internalResponse.Executions[0].ExecutionInfo.CompletionEvent).Return(completionEvent(), nil) + mockedSerializer.EXPECT().DeserializeResetPoints(internalResponse.Executions[0].ExecutionInfo.AutoResetPoints).Return(&types.ResetPoints{ + Points: []*types.ResetPointInfo{ + { + RunID: testRunID, + }, + }, + }, nil) + + mockedSerializer.EXPECT().DeserializeVersionHistories(internalResponse.Executions[0].VersionHistories).Return(&types.VersionHistories{ + CurrentVersionHistoryIndex: 1, + Histories: []*types.VersionHistory{ + { + BranchToken: []byte("branch-token-1"), + Items: []*types.VersionHistoryItem{ + { + EventID: 1, + Version: 1, + }, + }, + }, + { + BranchToken: []byte("branch-token-2"), + Items: []*types.VersionHistoryItem{ + { + EventID: 2, + Version: 1, + }, + { + EventID: 3, + Version: 2, + }, + }, + }, + }, + }, nil) + }, + checkRes: func(t *testing.T, response *ListConcreteExecutionsResponse, err error) { + executionInfo := sampleWorkflowExecutionInfo() + executionInfo.CompletionEvent = completionEvent() + executionInfo.AutoResetPoints = &types.ResetPoints{ + Points: []*types.ResetPointInfo{ + { + RunID: testRunID, + }, + }, + } + assert.Equal(t, &ListConcreteExecutionsResponse{ + Executions: []*ListConcreteExecutionsEntity{ + { + ExecutionInfo: executionInfo, + VersionHistories: &VersionHistories{ + CurrentVersionHistoryIndex: 1, + Histories: []*VersionHistory{ + { + BranchToken: []byte("branch-token-1"), + Items: []*VersionHistoryItem{ + { + EventID: 1, + Version: 1, + }, + }, + }, + { + BranchToken: []byte("branch-token-2"), + Items: []*VersionHistoryItem{ + { + EventID: 2, + Version: 1, + }, + { + EventID: 3, + Version: 2, + }, + }, + }, + }, + }, + }, + }, + PageToken: []byte("next"), + }, response) + }, + }, + { + name: "persistence error", + prepareMocks: func(mockedStore *MockExecutionStore, mockedSerializer *MockPayloadSerializer) { + mockedStore.EXPECT().ListConcreteExecutions(gomock.Any(), request).Return(nil, assert.AnError) + }, + checkRes: func(t *testing.T, response *ListConcreteExecutionsResponse, err error) { + assert.ErrorIs(t, err, assert.AnError) + }, + }, + { + name: "deserialize execution info error", + prepareMocks: func(mockedStore *MockExecutionStore, mockedSerializer *MockPayloadSerializer) { + mockedStore.EXPECT().ListConcreteExecutions(gomock.Any(), request).Return(internalResponse, nil) + mockedSerializer.EXPECT().DeserializeEvent(internalResponse.Executions[0].ExecutionInfo.CompletionEvent).Return(nil, assert.AnError) + }, + checkRes: func(t *testing.T, response *ListConcreteExecutionsResponse, err error) { + assert.ErrorIs(t, err, assert.AnError) + }, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + ctrl := gomock.NewController(t) + mockedStore := NewMockExecutionStore(ctrl) + mockedSerializer := NewMockPayloadSerializer(ctrl) + + tc.prepareMocks(mockedStore, mockedSerializer) + + manager := NewExecutionManagerImpl(mockedStore, testlogger.New(t), mockedSerializer) + + res, err := manager.ListConcreteExecutions(context.Background(), request) + + tc.checkRes(t, res, err) + }) + } +} + func sampleInternalActivityInfo(name string) *InternalActivityInfo { return &InternalActivityInfo{ Version: 1, diff --git a/common/persistence/versionHistory.go b/common/persistence/versionHistory.go index 18e7b56791a..0b31c23c2b5 100644 --- a/common/persistence/versionHistory.go +++ b/common/persistence/versionHistory.go @@ -108,7 +108,7 @@ func NewVersionHistoryFromInternalType( panic("version history is null") } - items := []*VersionHistoryItem{} + items := make([]*VersionHistoryItem, 0, len(input.Items)) for _, item := range input.Items { items = append(items, NewVersionHistoryItemFromInternalType(item)) }