From 0a3955d8686b43d278a3093f890ca114cdedbc6b Mon Sep 17 00:00:00 2001 From: Tim Li Date: Tue, 5 Mar 2024 10:53:38 -0800 Subject: [PATCH 1/2] Add Unit tests for persistence Task types --- .../persistence/dataManagerInterfaces_test.go | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/common/persistence/dataManagerInterfaces_test.go b/common/persistence/dataManagerInterfaces_test.go index 043309f1f39..d3b9cd7ac59 100644 --- a/common/persistence/dataManagerInterfaces_test.go +++ b/common/persistence/dataManagerInterfaces_test.go @@ -22,7 +22,9 @@ package persistence import ( "errors" + "fmt" "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -58,3 +60,65 @@ func TestIsTransientError(t *testing.T) { require.False(t, IsTransientError(err)) } } + +func TestIsTimeoutError(t *testing.T) { + notTimeoutError := fmt.Errorf("not timeout error") + assert.False(t, IsTimeoutError(notTimeoutError)) + assert.True(t, IsTimeoutError(&TimeoutError{})) +} + +func TestTaskCommonMethods(t *testing.T) { + timeNow := time.Now() + tasks := []interface{}{ + &ActivityTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow}, + &DecisionTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow}, + &RecordWorkflowStartedTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow}, + &ResetWorkflowTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow}, + &CloseExecutionTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow}, + &DeleteHistoryEventTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow}, + &DecisionTimeoutTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow}, + &ActivityTimeoutTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow}, + &UserTimerTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow}, + } + + for _, task := range tasks { + switch ty := task.(type) { + case *ActivityTask: + assert.Equal(t, TransferTaskTypeActivityTask, ty.GetType()) + case *DecisionTask: + assert.Equal(t, TransferTaskTypeDecisionTask, ty.GetType()) + case *RecordWorkflowStartedTask: + assert.Equal(t, TransferTaskTypeRecordWorkflowStarted, ty.GetType()) + case *ResetWorkflowTask: + assert.Equal(t, TransferTaskTypeResetWorkflow, ty.GetType()) + case *CloseExecutionTask: + assert.Equal(t, TransferTaskTypeCloseExecution, ty.GetType()) + case *DeleteHistoryEventTask: + assert.Equal(t, TaskTypeDeleteHistoryEvent, ty.GetType()) + case *DecisionTimeoutTask: + assert.Equal(t, TaskTypeDecisionTimeout, ty.GetType()) + case *ActivityTimeoutTask: + assert.Equal(t, TaskTypeActivityTimeout, ty.GetType()) + case *UserTimerTask: + assert.Equal(t, TaskTypeUserTimer, ty.GetType()) + default: + t.Fatalf("Unhandled task type: %T", t) + } + + // Test version methods + assert.Equal(t, int64(1), task.(Task).GetVersion()) + task.(Task).SetVersion(2) + assert.Equal(t, int64(2), task.(Task).GetVersion()) + + // Test TaskID methods + assert.Equal(t, int64(1), task.(Task).GetTaskID()) + task.(Task).SetTaskID(2) + assert.Equal(t, int64(2), task.(Task).GetTaskID()) + + // Test VisibilityTimestamp methods + assert.Equal(t, timeNow, task.(Task).GetVisibilityTimestamp()) + newTime := timeNow.Add(time.Second) + task.(Task).SetVisibilityTimestamp(newTime) + assert.Equal(t, newTime, task.(Task).GetVisibilityTimestamp()) + } +} From 6a14252d81c62f176852c6ad82b957e8658056fb Mon Sep 17 00:00:00 2001 From: Tim Li Date: Tue, 5 Mar 2024 12:29:45 -0800 Subject: [PATCH 2/2] Rename files based on comments. --- .../{dataManagerInterfaces.go => data_manager_interfaces.go} | 0 ...aManagerInterfaces_test.go => data_manager_interfaces_test.go} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename common/persistence/{dataManagerInterfaces.go => data_manager_interfaces.go} (100%) rename common/persistence/{dataManagerInterfaces_test.go => data_manager_interfaces_test.go} (100%) diff --git a/common/persistence/dataManagerInterfaces.go b/common/persistence/data_manager_interfaces.go similarity index 100% rename from common/persistence/dataManagerInterfaces.go rename to common/persistence/data_manager_interfaces.go diff --git a/common/persistence/dataManagerInterfaces_test.go b/common/persistence/data_manager_interfaces_test.go similarity index 100% rename from common/persistence/dataManagerInterfaces_test.go rename to common/persistence/data_manager_interfaces_test.go