Skip to content

Commit

Permalink
Added test cases for more util methods (#5755)
Browse files Browse the repository at this point in the history
  • Loading branch information
agautam478 authored Mar 8, 2024
1 parent b223d42 commit 8c1eba8
Showing 1 changed file with 156 additions and 5 deletions.
161 changes: 156 additions & 5 deletions common/persistence/nosql/nosql_execution_store_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package nosql

import (
"errors"
"testing"
"time"

Expand Down Expand Up @@ -223,7 +224,6 @@ func TestPrepareTasksForWorkflowTxn(t *testing.T) {
setupStore: func(store *nosqlExecutionStore) ([]*nosqlplugin.TimerTask, error) {
timerTasks := []persistence.Task{
&persistence.DecisionTimeoutTask{VisibilityTimestamp: time.Now(), TaskID: 1, EventID: 2, TimeoutType: 1, ScheduleAttempt: 1},
// Add more tasks as needed to fully test functionality
}
tasks, err := store.prepareTimerTasksForWorkflowTxn("domainID", "workflowID", "runID", timerTasks)
assert.NoError(t, err)
Expand All @@ -236,18 +236,19 @@ func TestPrepareTasksForWorkflowTxn(t *testing.T) {
name: "PrepareTimerTasksForWorkflowTxn - Unsupported Timer Task Type",
setupStore: func(store *nosqlExecutionStore) ([]*nosqlplugin.TimerTask, error) {
timerTasks := []persistence.Task{
&dummyTaskType{ // Using the dummy task type
&dummyTaskType{
VisibilityTimestamp: time.Now(),
TaskID: 1,
},
}
return store.prepareTimerTasksForWorkflowTxn("domainID-unsupported", "workflowID-unsupported", "runID-unsupported", timerTasks)
},
validate: func(t *testing.T, tasks []*nosqlplugin.TimerTask, err error) {
assert.Error(t, err) // Expecting an error due to unsupported timer task type
assert.Nil(t, tasks) // No tasks should be returned due to the error
assert.Error(t, err)
assert.Nil(t, tasks)
},
}}
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand All @@ -263,6 +264,156 @@ func TestPrepareTasksForWorkflowTxn(t *testing.T) {
}
}

func TestPrepareReplicationTasksForWorkflowTxn(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.ReplicationTask, error)
validate func(*testing.T, []*nosqlplugin.ReplicationTask, error)
}{
{
name: "Successful Replication Tasks Preparation",
setupStore: func(store *nosqlExecutionStore) ([]*nosqlplugin.ReplicationTask, error) {
replicationTasks := []persistence.Task{
&persistence.HistoryReplicationTask{
Version: 1,
},
}
return store.prepareReplicationTasksForWorkflowTxn("domainID", "workflowID", "runID", replicationTasks)
},
validate: func(t *testing.T, tasks []*nosqlplugin.ReplicationTask, err error) {
assert.NoError(t, err)
assert.NotEmpty(t, tasks)
},
},
{
name: "Handling Unknown Replication Task Type",
setupStore: func(store *nosqlExecutionStore) ([]*nosqlplugin.ReplicationTask, error) {
replicationTasks := []persistence.Task{
&dummyTaskType{
VisibilityTimestamp: time.Now(),
TaskID: -1,
},
}
return store.prepareReplicationTasksForWorkflowTxn("domainID", "workflowID", "runID", replicationTasks)
},
validate: func(t *testing.T, tasks []*nosqlplugin.ReplicationTask, 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)
})
}
}

func TestPrepareCrossClusterTasksForWorkflowTxn(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.CrossClusterTask, error)
validate func(*testing.T, []*nosqlplugin.CrossClusterTask, error)
}{
{
name: "Successful CrossCluster Tasks Preparation",
setupStore: func(store *nosqlExecutionStore) ([]*nosqlplugin.CrossClusterTask, error) {
crossClusterTasks := []persistence.Task{
&persistence.CrossClusterStartChildExecutionTask{
TargetCluster: "targetCluster",
},
}
return store.prepareCrossClusterTasksForWorkflowTxn("domainID", "workflowID", "runID", crossClusterTasks)
},
validate: func(t *testing.T, tasks []*nosqlplugin.CrossClusterTask, err error) {
assert.NoError(t, err)
assert.NotEmpty(t, tasks)
},
},
{
name: "Handling Unsupported CrossCluster Task Type",
setupStore: func(store *nosqlExecutionStore) ([]*nosqlplugin.CrossClusterTask, error) {
crossClusterTasks := []persistence.Task{
&dummyTaskType{ // Adjust this to be an unexpected type for cross-cluster tasks
VisibilityTimestamp: time.Now(),
TaskID: -1,
},
}
return store.prepareCrossClusterTasksForWorkflowTxn("domainID", "workflowID", "runID", crossClusterTasks)
},
validate: func(t *testing.T, tasks []*nosqlplugin.CrossClusterTask, err error) {
assert.Error(t, err) // Expecting an error due to unsupported task type
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)
})
}
}

func TestPrepareNoSQLTasksForWorkflowTxn(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, []*nosqlplugin.CrossClusterTask, []*nosqlplugin.ReplicationTask, []*nosqlplugin.TimerTask, error)
validate func(*testing.T, []*nosqlplugin.TransferTask, []*nosqlplugin.CrossClusterTask, []*nosqlplugin.ReplicationTask, []*nosqlplugin.TimerTask, error)
}{
{
name: "prepareNoSQLTasksForWorkflowTxn - Success",
setupStore: func(store *nosqlExecutionStore) ([]*nosqlplugin.TransferTask, []*nosqlplugin.CrossClusterTask, []*nosqlplugin.ReplicationTask, []*nosqlplugin.TimerTask, error) {
return nil, nil, nil, nil, nil
},
validate: func(t *testing.T, transferTasks []*nosqlplugin.TransferTask, crossClusterTasks []*nosqlplugin.CrossClusterTask, replicationTasks []*nosqlplugin.ReplicationTask, timerTasks []*nosqlplugin.TimerTask, err error) {
assert.NoError(t, err)
},
},
{
name: "prepareNoSQLTasksForWorkflowTxn - Task Preparation Failure",
setupStore: func(store *nosqlExecutionStore) ([]*nosqlplugin.TransferTask, []*nosqlplugin.CrossClusterTask, []*nosqlplugin.ReplicationTask, []*nosqlplugin.TimerTask, error) {
return nil, nil, nil, nil, errors.New("task preparation failed")
},
validate: func(t *testing.T, transferTasks []*nosqlplugin.TransferTask, crossClusterTasks []*nosqlplugin.CrossClusterTask, replicationTasks []*nosqlplugin.ReplicationTask, timerTasks []*nosqlplugin.TimerTask, err error) {
assert.Error(t, err)
assert.Nil(t, transferTasks)
assert.Nil(t, crossClusterTasks)
assert.Nil(t, replicationTasks)
assert.Nil(t, timerTasks)
},
},
}

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

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

0 comments on commit 8c1eba8

Please sign in to comment.