Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding unit tests for TestPrepareTransferTasksForWorkflowTxn #5763

Merged
merged 8 commits into from
Mar 14, 2024
55 changes: 55 additions & 0 deletions common/persistence/nosql/nosql_execution_store_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func TestNosqlExecutionStoreUtils(t *testing.T) {
tc.validate(t, req, err)
})
}

}

func TestPrepareTasksForWorkflowTxn(t *testing.T) {
Expand Down Expand Up @@ -414,6 +415,60 @@ func TestPrepareNoSQLTasksForWorkflowTxn(t *testing.T) {
}
}

func TestPrepareTransferTasksForWorkflowTxn(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

mockDB := nosqlplugin.NewMockDB(mockCtrl)
store := newTestNosqlExecutionStore(mockDB, log.NewNoop())
agautam478 marked this conversation as resolved.
Show resolved Hide resolved

testCases := []struct {
name string
setupStore func(*nosqlExecutionStore) ([]*nosqlplugin.TransferTask, error)
validate func(*testing.T, []*nosqlplugin.TransferTask, error)
}{
{
name: "Success - Prepare Transfer Tasks",
setupStore: func(store *nosqlExecutionStore) ([]*nosqlplugin.TransferTask, error) {
transferTasks := []persistence.Task{
&persistence.ActivityTask{
DomainID: "domainID",
TaskID: 1,
},
}
return store.prepareTransferTasksForWorkflowTxn("domainID", "workflowID", "runID", transferTasks)
},
validate: func(t *testing.T, tasks []*nosqlplugin.TransferTask, err error) {
assert.NoError(t, err)
assert.NotEmpty(t, tasks)
},
},
{
name: "Failure - Unsupported Task Type",
setupStore: func(store *nosqlExecutionStore) ([]*nosqlplugin.TransferTask, error) {
transferTasks := []persistence.Task{
&dummyTaskType{
VisibilityTimestamp: time.Now(),
TaskID: -1, // Using -1 to denote dummy/unsupported task
},
}
return store.prepareTransferTasksForWorkflowTxn("domainID", "workflowID", "runID", transferTasks)
},
validate: func(t *testing.T, tasks []*nosqlplugin.TransferTask, err error) {
assert.Error(t, err)
assert.Nil(t, tasks)
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tasks, err := tc.setupStore(store)
tc.validate(t, tasks, err)
})
}
}

type dummyTaskType struct {
persistence.Task
VisibilityTimestamp time.Time
Expand Down
Loading