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

Added additional unit tests testing history handler #6001

Merged
merged 1 commit into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
352 changes: 352 additions & 0 deletions service/history/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,358 @@ func (s *handlerSuite) TestRecordChildExecutionCompleted() {
}
}

func (s *handlerSuite) TestResetStickyTaskList() {
validInput := &types.HistoryResetStickyTaskListRequest{
DomainUUID: testDomainID,
Execution: &types.WorkflowExecution{
WorkflowID: testWorkflowID,
RunID: testValidUUID,
},
}

testInput := map[string]struct {
input *types.HistoryResetStickyTaskListRequest
expectedError bool
mockFn func()
}{
"shutting down": {
input: validInput,
expectedError: true,
mockFn: func() {
s.handler.shuttingDown = int32(1)
},
},
"empty domainID": {
input: &types.HistoryResetStickyTaskListRequest{
DomainUUID: "",
},
expectedError: true,
mockFn: func() {},
},
"ratelimit exceeded": {
input: validInput,
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(false).Times(1)
},
},
"getEngine error": {
input: validInput,
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
s.mockShardController.EXPECT().GetEngine(testWorkflowID).Return(nil, errors.New("error")).Times(1)
},
},
"resetStickyTaskList error": {
input: validInput,
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
s.mockShardController.EXPECT().GetEngine(testWorkflowID).Return(s.mockEngine, nil).Times(1)
s.mockEngine.EXPECT().ResetStickyTaskList(gomock.Any(), validInput).Return(nil, errors.New("error")).Times(1)
},
},
"success": {
input: validInput,
expectedError: false,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
s.mockShardController.EXPECT().GetEngine(testWorkflowID).Return(s.mockEngine, nil).Times(1)
s.mockEngine.EXPECT().ResetStickyTaskList(gomock.Any(), validInput).Return(&types.HistoryResetStickyTaskListResponse{}, nil).Times(1)
},
},
}

for name, input := range testInput {
s.Run(name, func() {
input.mockFn()
resp, err := s.handler.ResetStickyTaskList(context.Background(), input.input)
s.handler.shuttingDown = int32(0)
if input.expectedError {
s.Nil(resp)
s.Error(err)
} else {
s.NotNil(resp)
s.NoError(err)
}
})

}
}

func (s *handlerSuite) TestReplicateEventsV2() {
validInput := &types.ReplicateEventsV2Request{
DomainUUID: testDomainID,
WorkflowExecution: &types.WorkflowExecution{
WorkflowID: testWorkflowID,
RunID: testValidUUID,
},
VersionHistoryItems: []*types.VersionHistoryItem{
{
EventID: 1,
Version: 1,
},
},
Events: &types.DataBlob{
EncodingType: types.EncodingTypeThriftRW.Ptr(),
Data: []byte{1, 2, 3},
},
}

testInput := map[string]struct {
input *types.ReplicateEventsV2Request
expectedError bool
mockFn func()
}{
"shutting down": {
input: validInput,
expectedError: true,
mockFn: func() {
s.handler.shuttingDown = int32(1)
},
},
"empty domainID": {
input: &types.ReplicateEventsV2Request{
DomainUUID: "",
},
expectedError: true,
mockFn: func() {},
},
"ratelimit exceeded": {
input: validInput,
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(false).Times(1)
},
},
"getEngine error": {
input: validInput,
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
s.mockShardController.EXPECT().GetEngine(testWorkflowID).Return(nil, errors.New("error")).Times(1)
},
},
"replicateEventsV2 error": {
input: validInput,
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
s.mockShardController.EXPECT().GetEngine(testWorkflowID).Return(s.mockEngine, nil).Times(1)
s.mockEngine.EXPECT().ReplicateEventsV2(gomock.Any(), validInput).Return(errors.New("error")).Times(1)
},
},
"success": {
input: validInput,
expectedError: false,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
s.mockShardController.EXPECT().GetEngine(testWorkflowID).Return(s.mockEngine, nil).Times(1)
s.mockEngine.EXPECT().ReplicateEventsV2(gomock.Any(), validInput).Return(nil).Times(1)
},
},
}

for name, input := range testInput {
s.Run(name, func() {
input.mockFn()
err := s.handler.ReplicateEventsV2(context.Background(), input.input)
s.handler.shuttingDown = int32(0)
if input.expectedError {
s.Error(err)
} else {
s.NoError(err)
}
})
}
}

func (s *handlerSuite) TestSyncShardStatus() {
validInput := &types.SyncShardStatusRequest{
SourceCluster: "test",
ShardID: 1,
Timestamp: common.Int64Ptr(time.Now().UnixNano()),
}

testInput := map[string]struct {
input *types.SyncShardStatusRequest
expectedError bool
mockFn func()
}{
"shutting down": {
input: validInput,
expectedError: true,
mockFn: func() {
s.handler.shuttingDown = int32(1)
},
},
"ratelimit exceeded": {
input: validInput,
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(false).Times(1)
},
},
"get shard engine": {
input: validInput,
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
s.mockShardController.EXPECT().GetEngineForShard(int(validInput.ShardID)).Return(nil, errors.New("error")).Times(1)
},
},
"syncShardStatus error": {
input: validInput,
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
s.mockShardController.EXPECT().GetEngineForShard(int(validInput.ShardID)).Return(s.mockEngine, nil).Times(1)
s.mockEngine.EXPECT().SyncShardStatus(gomock.Any(), validInput).Return(errors.New("error")).Times(1)
},
},
"success": {
input: validInput,
expectedError: false,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
s.mockShardController.EXPECT().GetEngineForShard(int(validInput.ShardID)).Return(s.mockEngine, nil).Times(1)
s.mockEngine.EXPECT().SyncShardStatus(gomock.Any(), validInput).Return(nil).Times(1)
},
},
"empty sourceCluster": {
input: &types.SyncShardStatusRequest{
SourceCluster: "",
},
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
},
},
"missing timestamp": {
input: &types.SyncShardStatusRequest{
SourceCluster: "test",
},
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
},
},
}

for name, input := range testInput {
s.Run(name, func() {
input.mockFn()
err := s.handler.SyncShardStatus(context.Background(), input.input)
s.handler.shuttingDown = int32(0)
if input.expectedError {
s.Error(err)
} else {
s.NoError(err)
}
})
}
}

func (s *handlerSuite) TestSyncActivity() {
validInput := &types.SyncActivityRequest{
DomainID: testDomainID,
WorkflowID: testWorkflowID,
RunID: testValidUUID,
Version: 1,
ScheduledID: 1,
Details: []byte{1, 2, 3},
}

testInput := map[string]struct {
input *types.SyncActivityRequest
expectedError bool
mockFn func()
}{
"shutting down": {
input: validInput,
expectedError: true,
mockFn: func() {
s.handler.shuttingDown = int32(1)
},
},
"ratelimit exceeded": {
input: validInput,
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(false).Times(1)
},
},
"empty domainID": {
input: &types.SyncActivityRequest{
DomainID: "",
},
expectedError: true,
mockFn: func() {},
},
"empty workflowID": {
input: &types.SyncActivityRequest{
DomainID: testDomainID,
WorkflowID: "",
},
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
},
},
"empty runID": {
input: &types.SyncActivityRequest{
DomainID: testDomainID,
WorkflowID: testWorkflowID,
RunID: "",
},
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
},
},
"cannot get engine": {
input: validInput,
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
s.mockShardController.EXPECT().GetEngine(testWorkflowID).Return(nil, errors.New("error")).Times(1)
},
},
"syncActivity error": {
input: validInput,
expectedError: true,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
s.mockShardController.EXPECT().GetEngine(testWorkflowID).Return(s.mockEngine, nil).Times(1)
s.mockEngine.EXPECT().SyncActivity(gomock.Any(), validInput).Return(errors.New("error")).Times(1)
},
},
"success": {
input: validInput,
expectedError: false,
mockFn: func() {
s.mockRatelimiter.EXPECT().Allow().Return(true).Times(1)
s.mockShardController.EXPECT().GetEngine(testWorkflowID).Return(s.mockEngine, nil).Times(1)
s.mockEngine.EXPECT().SyncActivity(gomock.Any(), validInput).Return(nil).Times(1)
},
},
}

for name, input := range testInput {
s.Run(name, func() {
input.mockFn()
err := s.handler.SyncActivity(context.Background(), input.input)
s.handler.shuttingDown = int32(0)
if input.expectedError {
s.Error(err)
} else {
s.NoError(err)
}
})
}
}

func (s *handlerSuite) TestGetCrossClusterTasks() {
numShards := 10
targetCluster := cluster.TestAlternativeClusterName
Expand Down
Loading