Skip to content

Commit

Permalink
Tests for the stray lines needing coverage. (cadence-workflow#6098)
Browse files Browse the repository at this point in the history
* Covering the stray lines in various files

* One more test case

* One more test case
  • Loading branch information
agautam478 authored and timl3136 committed Jun 4, 2024
1 parent dd9f4ed commit 01fb0b2
Show file tree
Hide file tree
Showing 3 changed files with 258 additions and 2 deletions.
8 changes: 8 additions & 0 deletions service/frontend/wrappers/metered/metered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/uber-go/tally"
"go.uber.org/yarpc/yarpcerrors"

"github.com/uber/cadence/common/cache"
"github.com/uber/cadence/common/dynamicconfig"
Expand Down Expand Up @@ -714,6 +715,13 @@ func TestHandleErr(t *testing.T) {
expectedErrMsg: "client version not supported",
expectedCounter: "test.cadence_err_client_version_not_supported_counter+",
},
{
name: "YARPCDeadlineExceededError",
err: yarpcerrors.Newf(yarpcerrors.CodeDeadlineExceeded, "deadline exceeded"),
expectedErrType: &yarpcerrors.Status{},
expectedErrMsg: "deadline exceeded",
expectedCounter: "test.cadence_err_context_timeout_counter+",
},
{
name: "ContextDeadlineExceeded",
err: context.DeadlineExceeded,
Expand Down
37 changes: 35 additions & 2 deletions service/history/engine/engineimpl/start_workflow_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestStartWorkflowExecution(t *testing.T) {
Identity: "workflow-starter",
RequestID: "request-id-for-start",
WorkflowType: &types.WorkflowType{Name: "workflow-type"},
WorkflowIDReusePolicy: (*types.WorkflowIDReusePolicy)(common.Int32Ptr(1)),
WorkflowIDReusePolicy: types.WorkflowIDReusePolicyAllowDuplicate.Ptr(),
},
},
setupMocks: func(t *testing.T, eft *testdata.EngineForTest) {
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestStartWorkflowExecution(t *testing.T) {
Identity: "workflow-starter",
RequestID: "request-id-for-start",
WorkflowType: &types.WorkflowType{Name: "workflow-type"},
WorkflowIDReusePolicy: (*types.WorkflowIDReusePolicy)(common.Int32Ptr(3)),
WorkflowIDReusePolicy: types.WorkflowIDReusePolicyTerminateIfRunning.Ptr(),
},
},
setupMocks: func(t *testing.T, eft *testdata.EngineForTest) {
Expand All @@ -197,6 +197,39 @@ func TestStartWorkflowExecution(t *testing.T) {
},
wantErr: false,
},
{
name: "workflow ID reuse policy - reject duplicate",
request: &types.HistoryStartWorkflowExecutionRequest{
DomainUUID: constants.TestDomainID,
StartRequest: &types.StartWorkflowExecutionRequest{
Domain: constants.TestDomainName,
WorkflowID: "workflow-id",
WorkflowType: &types.WorkflowType{Name: "workflow-type"},
TaskList: &types.TaskList{Name: "default-task-list"},
ExecutionStartToCloseTimeoutSeconds: common.Int32Ptr(3600), // 1 hour
TaskStartToCloseTimeoutSeconds: common.Int32Ptr(10), // 10 seconds
Identity: "workflow-starter",
RequestID: "request-id-for-start",
WorkflowIDReusePolicy: types.WorkflowIDReusePolicyRejectDuplicate.Ptr(),
},
},
setupMocks: func(t *testing.T, eft *testdata.EngineForTest) {
domainEntry := &cache.DomainCacheEntry{}
eft.ShardCtx.Resource.DomainCache.EXPECT().GetDomainByID(constants.TestDomainID).Return(domainEntry, nil).AnyTimes()

eft.ShardCtx.Resource.ExecutionMgr.On("CreateWorkflowExecution", mock.Anything, mock.Anything).Return(nil, &persistence.WorkflowExecutionAlreadyStartedError{
StartRequestID: "existing-request-id",
RunID: "existing-run-id",
}).Once()
eft.ShardCtx.Resource.ShardMgr.
On("UpdateShard", mock.Anything, mock.Anything).
Return(nil)
historyV2Mgr := eft.ShardCtx.Resource.HistoryMgr
historyV2Mgr.On("AppendHistoryNodes", mock.Anything, mock.AnythingOfType("*persistence.AppendHistoryNodesRequest")).
Return(&persistence.AppendHistoryNodesResponse{}, nil).Once()
},
wantErr: true,
},
}

for _, tc := range tests {
Expand Down
215 changes: 215 additions & 0 deletions service/history/engine/engineimpl/terminate_workflow_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,221 @@ func TestTerminateWorkflowExecution(t *testing.T) {
},
wantErr: false,
},
{
name: "first execution run ID matches",
terminationRequest: types.HistoryTerminateWorkflowExecutionRequest{
DomainUUID: constants.TestDomainID,
TerminateRequest: &types.TerminateWorkflowExecutionRequest{
Domain: constants.TestDomainName,
WorkflowExecution: &types.WorkflowExecution{WorkflowID: constants.TestWorkflowID, RunID: constants.TestRunID},
Reason: "Test termination",
Identity: "testRunner",
FirstExecutionRunID: "matching-first-run-id",
},
},
setupMocks: func(t *testing.T, eft *testdata.EngineForTest) {
getExecReq := &persistence.GetWorkflowExecutionRequest{
DomainID: constants.TestDomainID,
Execution: types.WorkflowExecution{WorkflowID: constants.TestWorkflowID, RunID: constants.TestRunID},
DomainName: constants.TestDomainName,
RangeID: 1,
}
getExecResp := &persistence.GetWorkflowExecutionResponse{
State: &persistence.WorkflowMutableState{
ExecutionInfo: &persistence.WorkflowExecutionInfo{
DomainID: constants.TestDomainID,
WorkflowID: constants.TestWorkflowID,
RunID: constants.TestRunID,
FirstExecutionRunID: "matching-first-run-id",
},
ExecutionStats: &persistence.ExecutionStats{},
},
MutableStateStats: &persistence.MutableStateStats{},
}
eft.ShardCtx.Resource.ExecutionMgr.
On("GetWorkflowExecution", mock.Anything, getExecReq).
Return(getExecResp, nil).Once()

getCurrentExecReq := &persistence.GetCurrentExecutionRequest{
DomainID: constants.TestDomainID,
WorkflowID: constants.TestWorkflowID,
DomainName: constants.TestDomainName,
}
getCurrentExecResp := &persistence.GetCurrentExecutionResponse{
RunID: constants.TestRunID,
State: persistence.WorkflowStateRunning,
CloseStatus: persistence.WorkflowCloseStatusNone,
}
eft.ShardCtx.Resource.ExecutionMgr.
On("GetCurrentExecution", mock.Anything, getCurrentExecReq).
Return(getCurrentExecResp, nil).Once()

historyMgr := eft.ShardCtx.Resource.HistoryMgr
historyMgr.
On("ReadHistoryBranch", mock.Anything, mock.Anything).
Return(&persistence.ReadHistoryBranchResponse{}, nil).
Once()

updateExecResp := &persistence.UpdateWorkflowExecutionResponse{
MutableStateUpdateSessionStats: &persistence.MutableStateUpdateSessionStats{},
}
eft.ShardCtx.Resource.ExecutionMgr.
On("UpdateWorkflowExecution", mock.Anything, mock.Anything).
Return(updateExecResp, nil).Once()

eft.ShardCtx.Resource.ShardMgr.
On("UpdateShard", mock.Anything, mock.Anything).
Return(nil)

historyV2Mgr := eft.ShardCtx.Resource.HistoryMgr
historyV2Mgr.On("AppendHistoryNodes", mock.Anything, mock.AnythingOfType("*persistence.AppendHistoryNodesRequest")).
Return(&persistence.AppendHistoryNodesResponse{}, nil).Once()
},
wantErr: false,
},
{
name: "first execution run ID does not match",
terminationRequest: types.HistoryTerminateWorkflowExecutionRequest{
DomainUUID: constants.TestDomainID,
TerminateRequest: &types.TerminateWorkflowExecutionRequest{
Domain: constants.TestDomainName,
WorkflowExecution: &types.WorkflowExecution{WorkflowID: constants.TestWorkflowID, RunID: constants.TestRunID},
Reason: "Test termination",
Identity: "testRunner",
FirstExecutionRunID: "non-matching-first-run-id",
},
},
setupMocks: func(t *testing.T, eft *testdata.EngineForTest) {
getExecReq := &persistence.GetWorkflowExecutionRequest{
DomainID: constants.TestDomainID,
Execution: types.WorkflowExecution{WorkflowID: constants.TestWorkflowID, RunID: constants.TestRunID},
DomainName: constants.TestDomainName,
RangeID: 1,
}
getExecResp := &persistence.GetWorkflowExecutionResponse{
State: &persistence.WorkflowMutableState{
ExecutionInfo: &persistence.WorkflowExecutionInfo{
DomainID: constants.TestDomainID,
WorkflowID: constants.TestWorkflowID,
RunID: constants.TestRunID,
FirstExecutionRunID: "matching-first-run-id",
},
ExecutionStats: &persistence.ExecutionStats{},
},
MutableStateStats: &persistence.MutableStateStats{},
}
eft.ShardCtx.Resource.ExecutionMgr.
On("GetWorkflowExecution", mock.Anything, getExecReq).
Return(getExecResp, nil).Once()

getCurrentExecReq := &persistence.GetCurrentExecutionRequest{
DomainID: constants.TestDomainID,
WorkflowID: constants.TestWorkflowID,
DomainName: constants.TestDomainName,
}
getCurrentExecResp := &persistence.GetCurrentExecutionResponse{
RunID: constants.TestRunID,
State: persistence.WorkflowStateRunning,
CloseStatus: persistence.WorkflowCloseStatusNone,
}
eft.ShardCtx.Resource.ExecutionMgr.
On("GetCurrentExecution", mock.Anything, getCurrentExecReq).
Return(getCurrentExecResp, nil).Once()

historyMgr := eft.ShardCtx.Resource.HistoryMgr
historyMgr.
On("ReadHistoryBranch", mock.Anything, mock.Anything).
Return(&persistence.ReadHistoryBranchResponse{}, nil).
Once()

eft.ShardCtx.Resource.ExecutionMgr.
On("UpdateWorkflowExecution", mock.Anything, mock.Anything).
Return(&persistence.UpdateWorkflowExecutionResponse{}, nil).Once()
},
wantErr: true,
},
{
name: "load first execution run ID from start event",
terminationRequest: types.HistoryTerminateWorkflowExecutionRequest{
DomainUUID: constants.TestDomainID,
TerminateRequest: &types.TerminateWorkflowExecutionRequest{
Domain: constants.TestDomainName,
WorkflowExecution: &types.WorkflowExecution{WorkflowID: constants.TestWorkflowID, RunID: constants.TestRunID},
Reason: "Test termination",
Identity: "testRunner",
FirstExecutionRunID: "fetched-first-run-id",
},
},
setupMocks: func(t *testing.T, eft *testdata.EngineForTest) {
getExecReq := &persistence.GetWorkflowExecutionRequest{
DomainID: constants.TestDomainID,
Execution: types.WorkflowExecution{WorkflowID: constants.TestWorkflowID, RunID: constants.TestRunID},
DomainName: constants.TestDomainName,
RangeID: 1,
}
getExecResp := &persistence.GetWorkflowExecutionResponse{
State: &persistence.WorkflowMutableState{
ExecutionInfo: &persistence.WorkflowExecutionInfo{
DomainID: constants.TestDomainID,
WorkflowID: constants.TestWorkflowID,
RunID: constants.TestRunID,
FirstExecutionRunID: "",
},
ExecutionStats: &persistence.ExecutionStats{},
},
MutableStateStats: &persistence.MutableStateStats{},
}
eft.ShardCtx.Resource.ExecutionMgr.
On("GetWorkflowExecution", mock.Anything, getExecReq).
Return(getExecResp, nil).Once()

getCurrentExecReq := &persistence.GetCurrentExecutionRequest{
DomainID: constants.TestDomainID,
WorkflowID: constants.TestWorkflowID,
DomainName: constants.TestDomainName,
}
getCurrentExecResp := &persistence.GetCurrentExecutionResponse{
RunID: constants.TestRunID,
State: persistence.WorkflowStateRunning,
CloseStatus: persistence.WorkflowCloseStatusNone,
}
eft.ShardCtx.Resource.ExecutionMgr.
On("GetCurrentExecution", mock.Anything, getCurrentExecReq).
Return(getCurrentExecResp, nil).Once()

historyBranchResp := &persistence.ReadHistoryBranchResponse{
HistoryEvents: []*types.HistoryEvent{
{
ID: 1,
WorkflowExecutionStartedEventAttributes: &types.WorkflowExecutionStartedEventAttributes{
FirstExecutionRunID: "fetched-first-run-id",
},
},
},
}
historyMgr := eft.ShardCtx.Resource.HistoryMgr
historyMgr.
On("ReadHistoryBranch", mock.Anything, mock.Anything).
Return(historyBranchResp, nil).
Once()

updateExecResp := &persistence.UpdateWorkflowExecutionResponse{
MutableStateUpdateSessionStats: &persistence.MutableStateUpdateSessionStats{},
}
eft.ShardCtx.Resource.ExecutionMgr.
On("UpdateWorkflowExecution", mock.Anything, mock.Anything).
Return(updateExecResp, nil).Once()

eft.ShardCtx.Resource.ShardMgr.
On("UpdateShard", mock.Anything, mock.Anything).
Return(nil)

historyV2Mgr := eft.ShardCtx.Resource.HistoryMgr
historyV2Mgr.On("AppendHistoryNodes", mock.Anything, mock.AnythingOfType("*persistence.AppendHistoryNodesRequest")).
Return(&persistence.AppendHistoryNodesResponse{}, nil).Once()
},
wantErr: false,
},
}

for _, tc := range tests {
Expand Down

0 comments on commit 01fb0b2

Please sign in to comment.