Skip to content

Commit

Permalink
Added tests for GetTasks
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobht committed May 24, 2024
1 parent fb4bfce commit 21ee0ac
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions common/persistence/nosql/nosql_task_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ package nosql
import (
"context"
"testing"
"time"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/log"
"github.com/uber/cadence/common/persistence"
"github.com/uber/cadence/common/persistence/nosql/nosqlplugin"
Expand All @@ -39,6 +41,8 @@ const (
TestDomainID = "test-domain-id"
TestDomainName = "test-domain"
TestTaskListName = "test-tasklist"
TestWorkflowID = "test-workflow-id"
TestRunID = "test-run-id"
)

func TestNewNoSQLStore(t *testing.T) {
Expand Down Expand Up @@ -115,3 +119,83 @@ func TestGetTaskListSize(t *testing.T) {
size,
)
}

func TestGetTasks(t *testing.T) {
store, db := setupNoSQLStoreMocks(t)
now := time.Unix(123, 456)

taskrow1 := nosqlplugin.TaskRow{
DomainID: TestDomainID,
TaskListName: TestTaskListName,
TaskListType: int(types.TaskListTypeDecision),
TaskID: 5,
WorkflowID: TestWorkflowID,
RunID: TestRunID,
ScheduledID: 0,
CreatedTime: now,
PartitionConfig: nil,
}

taskrow2 := taskrow1
taskrow2.TaskID = 6

db.EXPECT().SelectTasks(gomock.Any(), &nosqlplugin.TasksFilter{
TaskListFilter: *getExpectedTaskListFilter(),
BatchSize: 100,
MinTaskID: 1,
MaxTaskID: 15,
}).Return([]*nosqlplugin.TaskRow{&taskrow1, &taskrow2}, nil)

resp, err := store.GetTasks(context.Background(), getValidGetTasksRequest())

assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Len(t, resp.Tasks, 2)
taskRowEqualTaskInfo(t, taskrow1, resp.Tasks[0])
taskRowEqualTaskInfo(t, taskrow2, resp.Tasks[1])
}

func TestGetTasks_Empty(t *testing.T) {
store, _ := setupNoSQLStoreMocks(t)

request := getValidGetTasksRequest()
// Set the max read level to be less than the min read level
request.ReadLevel = 10
request.MaxReadLevel = common.Int64Ptr(5)
resp, err := store.GetTasks(context.Background(), request)

assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Empty(t, resp.Tasks)
}

func taskRowEqualTaskInfo(t *testing.T, taskrow1 nosqlplugin.TaskRow, taskInfo1 *persistence.InternalTaskInfo) {
assert.Equal(t, taskrow1.DomainID, taskInfo1.DomainID)
assert.Equal(t, taskrow1.WorkflowID, taskInfo1.WorkflowID)
assert.Equal(t, taskrow1.RunID, taskInfo1.RunID)
assert.Equal(t, taskrow1.TaskID, taskInfo1.TaskID)
assert.Equal(t, taskrow1.ScheduledID, taskInfo1.ScheduleID)
assert.Equal(t, taskrow1.CreatedTime, taskInfo1.CreatedTime)
assert.Equal(t, taskrow1.PartitionConfig, taskInfo1.PartitionConfig)
}

func getValidGetTasksRequest() *persistence.GetTasksRequest {
return &persistence.GetTasksRequest{
DomainID: TestDomainID,
DomainName: TestDomainName,
TaskList: TestTaskListName,
TaskType: int(types.TaskListTypeDecision),
// The read level is the smallest taskID that we want to read, the maxReadLevel is the largest
ReadLevel: 1,
MaxReadLevel: common.Int64Ptr(15),
BatchSize: 100,
}
}

func getExpectedTaskListFilter() *nosqlplugin.TaskListFilter {
return &nosqlplugin.TaskListFilter{
DomainID: TestDomainID,
TaskListName: TestTaskListName,
TaskListType: int(types.TaskListTypeDecision),
}
}

0 comments on commit 21ee0ac

Please sign in to comment.