Skip to content

Commit

Permalink
Add unit tests for the remaining util functions in data_manager_inter…
Browse files Browse the repository at this point in the history
…faces (#5742)
  • Loading branch information
timl3136 authored Mar 7, 2024
1 parent 83f9aca commit b34ee0b
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions common/persistence/data_manager_interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ func TestIsTimeoutError(t *testing.T) {
assert.True(t, IsTimeoutError(&TimeoutError{}))
}

func TestIsBackgroundTransientError(t *testing.T) {
transientErrors := map[error]bool{
&types.ServiceBusyError{}: false,
&types.InternalServiceError{}: true,
&TimeoutError{}: true,
}
for error, result := range transientErrors {
assert.Equal(t, result, IsBackgroundTransientError(error))
}
}

func TestTaskCommonMethods(t *testing.T) {
timeNow := time.Now()
tasks := []Task{
Expand Down Expand Up @@ -189,6 +200,52 @@ func TestOnlyGetTypeTask(t *testing.T) {
}
}

func TestNewHistoryBranch(t *testing.T) {
newTreeID := "newTreeID"
generalToken, err := NewHistoryBranchToken(newTreeID)
assert.NoError(t, err)
assert.NotEmpty(t, generalToken)

newBranchID := "newBranchID"
branchToken, err := NewHistoryBranchTokenByBranchID(newTreeID, newBranchID)
assert.NoError(t, err)
assert.NotEmpty(t, branchToken)

anotherBranchToken, err := NewHistoryBranchTokenFromAnother(newBranchID, generalToken)
assert.NoError(t, err)
assert.NotEmpty(t, anotherBranchToken)
}

func TestHistoryGarbageCleanupInfo(t *testing.T) {
testDomainID := "testDomainID"
testWorkflowID := "testWorkflowID"
testRunID := "testRunID"
actualInfo := BuildHistoryGarbageCleanupInfo(testDomainID, testWorkflowID, testRunID)
splitDomainID, splitWorkflowID, splitRunID, splitError := SplitHistoryGarbageCleanupInfo(actualInfo)
assert.Equal(t, testDomainID, splitDomainID)
assert.Equal(t, testWorkflowID, splitWorkflowID)
assert.Equal(t, testRunID, splitRunID)
assert.NoError(t, splitError)
_, _, _, splitError = SplitHistoryGarbageCleanupInfo("invalidInfo")
assert.Error(t, splitError)
}

func TestNewGetReplicationTasksFromDLQRequest(t *testing.T) {
sourceCluster := "testSourceCluster"
readLevel := int64(1)
maxReadLevel := int64(2)
batchSize := 10
tasksRequest := NewGetReplicationTasksFromDLQRequest(sourceCluster, readLevel, maxReadLevel, batchSize, nil)
assert.Equal(t, sourceCluster, tasksRequest.SourceClusterName)
}

func TestHasMoreRowsToDelete(t *testing.T) {
assert.True(t, HasMoreRowsToDelete(10, 10))
assert.False(t, HasMoreRowsToDelete(11, 10))
assert.False(t, HasMoreRowsToDelete(9, 10))
assert.False(t, HasMoreRowsToDelete(-1, 10))

}
func TestTransferTaskInfo(t *testing.T) {
timeNow := time.Now()
task := &TransferTaskInfo{
Expand Down

0 comments on commit b34ee0b

Please sign in to comment.