Skip to content

Commit

Permalink
Add more unit tests for persistence task types in DataManagerInterfac…
Browse files Browse the repository at this point in the history
…es (#5726)

* Add unit tests for remaining common task types in data_manager_interfaces, also add unit test for several child task types
  • Loading branch information
timl3136 authored Mar 6, 2024
1 parent cb39e82 commit 45d755e
Showing 1 changed file with 76 additions and 10 deletions.
86 changes: 76 additions & 10 deletions common/persistence/data_manager_interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestIsTimeoutError(t *testing.T) {

func TestTaskCommonMethods(t *testing.T) {
timeNow := time.Now()
tasks := []interface{}{
tasks := []Task{
&ActivityTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&DecisionTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&RecordWorkflowStartedTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
Expand All @@ -79,6 +79,19 @@ func TestTaskCommonMethods(t *testing.T) {
&DecisionTimeoutTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&ActivityTimeoutTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&UserTimerTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&ActivityRetryTimerTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&WorkflowBackoffTimerTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&WorkflowTimeoutTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&CancelExecutionTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&SignalExecutionTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&RecordChildExecutionCompletedTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&ApplyParentClosePolicyTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&UpsertWorkflowSearchAttributesTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&StartChildExecutionTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&RecordWorkflowClosedTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&HistoryReplicationTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&SyncActivityTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
&FailoverMarkerTask{Version: 1, TaskID: 1, VisibilityTimestamp: timeNow},
}

for _, task := range tasks {
Expand All @@ -101,24 +114,77 @@ func TestTaskCommonMethods(t *testing.T) {
assert.Equal(t, TaskTypeActivityTimeout, ty.GetType())
case *UserTimerTask:
assert.Equal(t, TaskTypeUserTimer, ty.GetType())
case *ActivityRetryTimerTask:
assert.Equal(t, TaskTypeActivityRetryTimer, ty.GetType())
case *WorkflowBackoffTimerTask:
assert.Equal(t, TaskTypeWorkflowBackoffTimer, ty.GetType())
case *WorkflowTimeoutTask:
assert.Equal(t, TaskTypeWorkflowTimeout, ty.GetType())
case *CancelExecutionTask:
assert.Equal(t, TransferTaskTypeCancelExecution, ty.GetType())
case *SignalExecutionTask:
assert.Equal(t, TransferTaskTypeSignalExecution, ty.GetType())
case *RecordChildExecutionCompletedTask:
assert.Equal(t, TransferTaskTypeRecordChildExecutionCompleted, ty.GetType())
case *ApplyParentClosePolicyTask:
assert.Equal(t, TransferTaskTypeApplyParentClosePolicy, ty.GetType())
case *UpsertWorkflowSearchAttributesTask:
assert.Equal(t, TransferTaskTypeUpsertWorkflowSearchAttributes, ty.GetType())
case *StartChildExecutionTask:
assert.Equal(t, TransferTaskTypeStartChildExecution, ty.GetType())
case *RecordWorkflowClosedTask:
assert.Equal(t, TransferTaskTypeRecordWorkflowClosed, ty.GetType())
case *HistoryReplicationTask:
assert.Equal(t, ReplicationTaskTypeHistory, ty.GetType())
case *SyncActivityTask:
assert.Equal(t, ReplicationTaskTypeSyncActivity, ty.GetType())
case *FailoverMarkerTask:
assert.Equal(t, ReplicationTaskTypeFailoverMarker, 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())
assert.Equal(t, int64(1), task.GetVersion())
task.SetVersion(2)
assert.Equal(t, int64(2), 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())
assert.Equal(t, int64(1), task.GetTaskID())
task.SetTaskID(2)
assert.Equal(t, int64(2), task.GetTaskID())

// Test VisibilityTimestamp methods
assert.Equal(t, timeNow, task.(Task).GetVisibilityTimestamp())
assert.Equal(t, timeNow, task.GetVisibilityTimestamp())
newTime := timeNow.Add(time.Second)
task.(Task).SetVisibilityTimestamp(newTime)
assert.Equal(t, newTime, task.(Task).GetVisibilityTimestamp())
task.SetVisibilityTimestamp(newTime)
assert.Equal(t, newTime, task.GetVisibilityTimestamp())
}
}

func TestOnlyGetTypeTask(t *testing.T) {
tasks := []Task{
&CrossClusterStartChildExecutionTask{},
&CrossClusterCancelExecutionTask{},
&CrossClusterSignalExecutionTask{},
&CrossClusterRecordChildExecutionCompletedTask{},
&CrossClusterApplyParentClosePolicyTask{},
}

for _, task := range tasks {
switch ty := task.(type) {
case *CrossClusterStartChildExecutionTask:
assert.Equal(t, CrossClusterTaskTypeStartChildExecution, ty.GetType())
case *CrossClusterCancelExecutionTask:
assert.Equal(t, CrossClusterTaskTypeCancelExecution, ty.GetType())
case *CrossClusterSignalExecutionTask:
assert.Equal(t, CrossClusterTaskTypeSignalExecution, ty.GetType())
case *CrossClusterRecordChildExecutionCompletedTask:
assert.Equal(t, CrossClusterTaskTypeRecordChildExeuctionCompleted, ty.GetType())
case *CrossClusterApplyParentClosePolicyTask:
assert.Equal(t, CrossClusterTaskTypeApplyParentClosePolicy, ty.GetType())
default:
t.Fatalf("Unhandled task type: %T", t)
}
}
}

0 comments on commit 45d755e

Please sign in to comment.