Skip to content

Commit

Permalink
Add addition unit tests and comment out unused code in workflow parsi…
Browse files Browse the repository at this point in the history
…ng utils functions (cadence-workflow#5870)

* Add additional unit tests to workflow parsing utils functions, also remove part of the function that would never be called
  • Loading branch information
timl3136 authored Apr 5, 2024
1 parent 9af0e32 commit d6b6c47
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -542,19 +542,7 @@ func parseTransferTaskInfo(
func parseCrossClusterTaskInfo(
result map[string]interface{},
) *persistence.CrossClusterTaskInfo {
info := (*persistence.CrossClusterTaskInfo)(parseTransferTaskInfo(result))
if persistence.CrossClusterTaskDefaultTargetRunID == persistence.TransferTaskTransferTargetRunID {
return info
}

// incase CrossClusterTaskDefaultTargetRunID is updated and not equal to TransferTaskTransferTargetRunID
if v, ok := result["target_run_id"]; ok {
info.TargetRunID = v.(gocql.UUID).String()
if info.TargetRunID == persistence.CrossClusterTaskDefaultTargetRunID {
info.TargetRunID = ""
}
}
return info
return parseTransferTaskInfo(result)
}

func parseReplicationTaskInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/persistence"
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin"
)

type mockUUID struct {
Expand Down Expand Up @@ -362,3 +363,161 @@ func Test_parseActivityInfo(t *testing.T) {

assert.Equal(t, expected, parseActivityInfo("domain_id", testInput))
}

func Test_parseTimerInfo(t *testing.T) {
timeNow := time.Now()
testInput := map[string]interface{}{
"version": int64(1),
"timer_id": "timer_id",
"started_id": int64(2),
"expiry_time": timeNow,
"task_id": int64(3),
}
expected := &persistence.TimerInfo{
Version: int64(1),
TimerID: "timer_id",
StartedID: int64(2),
ExpiryTime: timeNow,
TaskStatus: int64(3),
}
assert.Equal(t, expected, parseTimerInfo(testInput))
}

func Test_parseChildExecutionInfo(t *testing.T) {
startedRunID := newMockUUID("started_run_id")
createRequestID := newMockUUID("create_request_id")
domainID := newMockUUID("domain_id")
testInput := map[string]interface{}{
"version": int64(1),
"initiated_id": int64(2),
"initiated_event_batch_id": int64(3),
"initiated_event": []byte("initiated_event"),
"started_id": int64(4),
"started_workflow_id": "started_workflow_id",
"started_run_id": startedRunID,
"started_event": []byte("started_event"),
"create_request_id": createRequestID,
"event_data_encoding": "Proto3",
"domain_id": domainID,
"workflow_type_name": "workflow_type_name",
"parent_close_policy": 1,
}
expected := &persistence.InternalChildExecutionInfo{
Version: int64(1),
InitiatedID: int64(2),
InitiatedEventBatchID: int64(3),
InitiatedEvent: persistence.NewDataBlob([]byte("initiated_event"), "Proto3"),
StartedID: int64(4),
StartedWorkflowID: "started_workflow_id",
StartedRunID: startedRunID.String(),
StartedEvent: persistence.NewDataBlob([]byte("started_event"), "Proto3"),
CreateRequestID: createRequestID.String(),
DomainID: domainID.String(),
WorkflowTypeName: "workflow_type_name",
ParentClosePolicy: 1,
}
assert.Equal(t, expected, parseChildExecutionInfo(testInput))

// edge case
testInput = map[string]interface{}{
"domain_id": newMockUUID(_emptyUUID.String()),
"domain_name": "domain_name",
}
assert.Equal(t, "domain_name", parseChildExecutionInfo(testInput).DomainNameDEPRECATED)
assert.Equal(t, "", parseChildExecutionInfo(testInput).DomainID)
}

func Test_parseRequestCancelInfo(t *testing.T) {
testInput := map[string]interface{}{
"version": int64(1),
"initiated_id": int64(2),
"initiated_event_batch_id": int64(3),
"cancel_request_id": "cancel_request_id",
}
expected := &persistence.RequestCancelInfo{
Version: int64(1),
InitiatedID: int64(2),
InitiatedEventBatchID: int64(3),
CancelRequestID: "cancel_request_id",
}
assert.Equal(t, expected, parseRequestCancelInfo(testInput))
}

func Test_parseSignalInfo(t *testing.T) {
testInput := map[string]interface{}{
"version": int64(1),
"initiated_id": int64(2),
"initiated_event_batch_id": int64(3),
"signal_request_id": newMockUUID("signal_request_id"),
"signal_name": "signal_name",
"input": []byte("input"),
"control": []byte("control"),
}
expected := &persistence.SignalInfo{
Version: int64(1),
InitiatedID: int64(2),
InitiatedEventBatchID: int64(3),
SignalName: "signal_name",
SignalRequestID: "signal_request_id",
Input: []byte("input"),
Control: []byte("control"),
}
assert.Equal(t, expected, parseSignalInfo(testInput))
}

func Test_parseTimerTaskInfo(t *testing.T) {
timeNow := time.Now()
testInput := map[string]interface{}{
"version": int64(1),
"visibility_ts": timeNow,
"task_id": int64(2),
"run_id": newMockUUID("run_id"),
"type": 3,
"timeout_type": 3,
"event_id": int64(4),
"schedule_attempt": int64(5),
}
expected := &persistence.TimerTaskInfo{
Version: int64(1),
VisibilityTimestamp: timeNow,
TaskID: int64(2),
RunID: "run_id",
TaskType: 3,
TimeoutType: 3,
EventID: int64(4),
ScheduleAttempt: int64(5),
}
assert.Equal(t, expected, parseTimerTaskInfo(testInput))
}

func Test_parseReplicationTaskInfo(t *testing.T) {
testInput := map[string]interface{}{
"domain_id": newMockUUID("domain_id"),
"workflow_id": "workflow_id",
"run_id": newMockUUID("run_id"),
"task_id": int64(1),
"type": 2,
"first_event_id": int64(3),
"next_event_id": int64(4),
"version": int64(5),
"scheduled_id": int64(6),
"branch_token": []byte("branch_token"),
"new_run_branch_token": []byte("new_run_branch_token"),
"created_time": int64(7),
}
expected := &nosqlplugin.ReplicationTask{
DomainID: "domain_id",
WorkflowID: "workflow_id",
RunID: "run_id",
TaskID: int64(1),
TaskType: 2,
FirstEventID: int64(3),
NextEventID: int64(4),
Version: int64(5),
ScheduledID: int64(6),
BranchToken: []byte("branch_token"),
NewRunBranchToken: []byte("new_run_branch_token"),
CreationTime: time.Unix(0, 7),
}
assert.Equal(t, expected, parseReplicationTaskInfo(testInput))
}

0 comments on commit d6b6c47

Please sign in to comment.