From 87bf878eb600a13a39d1da1624071502f5728bf2 Mon Sep 17 00:00:00 2001 From: Aditi Gautam Date: Thu, 7 Mar 2024 17:36:17 -0800 Subject: [PATCH 1/2] Adding unit tests for TestPrepareTransferTasksForWorkflowTxn --- .../nosql/nosql_execution_store_util_test.go | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/common/persistence/nosql/nosql_execution_store_util_test.go b/common/persistence/nosql/nosql_execution_store_util_test.go index 01b15c5cfb8..8f9b60e873d 100644 --- a/common/persistence/nosql/nosql_execution_store_util_test.go +++ b/common/persistence/nosql/nosql_execution_store_util_test.go @@ -212,6 +212,7 @@ func TestNosqlExecutionStoreUtils(t *testing.T) { tc.validate(t, req, err) }) } + } func TestPrepareTasksForWorkflowTxn(t *testing.T) { @@ -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()) + + 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 From 05916d9e02de4c0ee8ebdfcc169c7ac044b32e3b Mon Sep 17 00:00:00 2001 From: Aditi Gautam Date: Tue, 12 Mar 2024 10:05:41 -0700 Subject: [PATCH 2/2] Resolved code comments --- .../nosql/nosql_execution_store_util_test.go | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/common/persistence/nosql/nosql_execution_store_util_test.go b/common/persistence/nosql/nosql_execution_store_util_test.go index 8f9b60e873d..4073f0f41f7 100644 --- a/common/persistence/nosql/nosql_execution_store_util_test.go +++ b/common/persistence/nosql/nosql_execution_store_util_test.go @@ -416,28 +416,21 @@ 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()) - testCases := []struct { name string - setupStore func(*nosqlExecutionStore) ([]*nosqlplugin.TransferTask, error) + tasks []persistence.Task + expectFunc func(*nosqlplugin.MockDB) 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) + tasks: []persistence.Task{ + &persistence.ActivityTask{ + DomainID: "domainID", + TaskID: 1, + }, }, + expectFunc: func(mockDB *nosqlplugin.MockDB) {}, validate: func(t *testing.T, tasks []*nosqlplugin.TransferTask, err error) { assert.NoError(t, err) assert.NotEmpty(t, tasks) @@ -445,15 +438,13 @@ func TestPrepareTransferTasksForWorkflowTxn(t *testing.T) { }, { 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) + tasks: []persistence.Task{ + &dummyTaskType{ + VisibilityTimestamp: time.Now(), + TaskID: -1, + }, }, + expectFunc: func(mockDB *nosqlplugin.MockDB) {}, validate: func(t *testing.T, tasks []*nosqlplugin.TransferTask, err error) { assert.Error(t, err) assert.Nil(t, tasks) @@ -463,8 +454,18 @@ func TestPrepareTransferTasksForWorkflowTxn(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - tasks, err := tc.setupStore(store) - tc.validate(t, tasks, err) + mockCtrl := gomock.NewController(t) + defer mockCtrl.Finish() + + mockDB := nosqlplugin.NewMockDB(mockCtrl) + store := newTestNosqlExecutionStore(mockDB, log.NewNoop()) + + if tc.expectFunc != nil { + tc.expectFunc(mockDB) // Set up any expectations on the mockDB + } + + tasks, err := store.prepareTransferTasksForWorkflowTxn("domainID", "workflowID", "runID", tc.tasks) + tc.validate(t, tasks, err) // Validate the output }) } } @@ -476,7 +477,7 @@ type dummyTaskType struct { } func (d *dummyTaskType) GetType() int { - return 999 // Using a type that is not expected by switch statement + return 999 // Using a type that is not expected by the switch statement } func (d *dummyTaskType) GetVersion() int64 {