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 unit tests for Delete current and workflow execution, list all … #5733

Merged
merged 3 commits into from
Mar 6, 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
111 changes: 105 additions & 6 deletions common/persistence/nosql/nosql_execution_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ func TestNosqlExecutionStore(t *testing.T) {
SelectWorkflowExecution(ctx, shardID, gomock.Any(), gomock.Any(), gomock.Any()).
Return(nil, &types.EntityNotExistsError{}).Times(1)
mockDB.EXPECT().IsNotFoundError(gomock.Any()).Return(true).AnyTimes()
mockDB.EXPECT().IsTimeoutError(gomock.Any()).Return(false).AnyTimes()
mockDB.EXPECT().IsThrottlingError(gomock.Any()).Return(false).AnyTimes()
mockDB.EXPECT().IsDBUnavailableError(gomock.Any()).Return(false).AnyTimes()
return newTestNosqlExecutionStore(mockDB, log.NewNoop())
},
testFunc: func(store *nosqlExecutionStore) error {
Expand Down Expand Up @@ -224,16 +221,118 @@ func TestNosqlExecutionStore(t *testing.T) {
UpdateWorkflowExecutionWithTasks(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Nil(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(errors.New("database is unavailable")).Times(1)
mockDB.EXPECT().IsNotFoundError(gomock.Any()).Return(true).AnyTimes()
mockDB.EXPECT().IsTimeoutError(gomock.Any()).Return(false).AnyTimes()
mockDB.EXPECT().IsThrottlingError(gomock.Any()).Return(false).AnyTimes()
mockDB.EXPECT().IsDBUnavailableError(gomock.Any()).Return(false).AnyTimes()
return newTestNosqlExecutionStore(mockDB, log.NewNoop())
},
testFunc: func(store *nosqlExecutionStore) error {
return store.UpdateWorkflowExecution(ctx, newUpdateWorkflowExecutionRequest())
},
expectedError: &types.InternalServiceError{Message: "database is unavailable"},
},
{
name: "DeleteWorkflowExecution success",
setupMock: func(ctrl *gomock.Controller) *nosqlExecutionStore {
mockDB := nosqlplugin.NewMockDB(ctrl)
mockDB.EXPECT().
DeleteWorkflowExecution(ctx, shardID, gomock.Any(), gomock.Any(), gomock.Any()).
Return(nil)
return newTestNosqlExecutionStore(mockDB, log.NewNoop())
},
testFunc: func(store *nosqlExecutionStore) error {
return store.DeleteWorkflowExecution(ctx, &persistence.DeleteWorkflowExecutionRequest{
DomainID: "domainID",
WorkflowID: "workflowID",
RunID: "runID",
})
},
expectedError: nil,
},
{
name: "DeleteWorkflowExecution failure - workflow does not exist",
setupMock: func(ctrl *gomock.Controller) *nosqlExecutionStore {
mockDB := nosqlplugin.NewMockDB(ctrl)
mockDB.EXPECT().
DeleteWorkflowExecution(ctx, shardID, gomock.Any(), gomock.Any(), gomock.Any()).
Return(&types.EntityNotExistsError{Message: "workflow does not exist"})
mockDB.EXPECT().IsNotFoundError(gomock.Any()).Return(true).AnyTimes()
return newTestNosqlExecutionStore(mockDB, log.NewNoop())
},
testFunc: func(store *nosqlExecutionStore) error {
return store.DeleteWorkflowExecution(ctx, &persistence.DeleteWorkflowExecutionRequest{
DomainID: "domainID",
WorkflowID: "workflowID",
RunID: "runID",
})
},
expectedError: &types.EntityNotExistsError{Message: "workflow does not exist"},
},
{
name: "DeleteCurrentWorkflowExecution success",
setupMock: func(ctrl *gomock.Controller) *nosqlExecutionStore {
mockDB := nosqlplugin.NewMockDB(ctrl)
mockDB.EXPECT().
DeleteCurrentWorkflow(ctx, shardID, gomock.Any(), gomock.Any(), gomock.Any()).
Return(nil)
return newTestNosqlExecutionStore(mockDB, log.NewNoop())
},
testFunc: func(store *nosqlExecutionStore) error {
return store.DeleteCurrentWorkflowExecution(ctx, &persistence.DeleteCurrentWorkflowExecutionRequest{
DomainID: "domainID",
WorkflowID: "workflowID",
RunID: "runID",
})
},
expectedError: nil,
},
{
name: "DeleteCurrentWorkflowExecution failure - current workflow does not exist",
setupMock: func(ctrl *gomock.Controller) *nosqlExecutionStore {
mockDB := nosqlplugin.NewMockDB(ctrl)
mockDB.EXPECT().
DeleteCurrentWorkflow(ctx, shardID, gomock.Any(), gomock.Any(), gomock.Any()).
Return(&types.EntityNotExistsError{Message: "current workflow does not exist"})
mockDB.EXPECT().IsNotFoundError(gomock.Any()).Return(true).AnyTimes()
return newTestNosqlExecutionStore(mockDB, log.NewNoop())
},
testFunc: func(store *nosqlExecutionStore) error {
return store.DeleteCurrentWorkflowExecution(ctx, &persistence.DeleteCurrentWorkflowExecutionRequest{
DomainID: "domainID",
WorkflowID: "workflowID",
RunID: "runID",
})
},
expectedError: &types.EntityNotExistsError{Message: "current workflow does not exist"},
},
{
name: "ListCurrentExecutions success",
setupMock: func(ctrl *gomock.Controller) *nosqlExecutionStore {
mockDB := nosqlplugin.NewMockDB(ctrl)
mockDB.EXPECT().
SelectAllCurrentWorkflows(ctx, shardID, gomock.Any(), gomock.Any()).
Return([]*persistence.CurrentWorkflowExecution{}, nil, nil)
return newTestNosqlExecutionStore(mockDB, log.NewNoop())
},
testFunc: func(store *nosqlExecutionStore) error {
_, err := store.ListCurrentExecutions(ctx, &persistence.ListCurrentExecutionsRequest{})
return err
},
expectedError: nil,
},
{
name: "ListCurrentExecutions failure - database error",
setupMock: func(ctrl *gomock.Controller) *nosqlExecutionStore {
mockDB := nosqlplugin.NewMockDB(ctrl)
mockDB.EXPECT().
SelectAllCurrentWorkflows(ctx, shardID, gomock.Any(), gomock.Any()).
Return(nil, nil, errors.New("database error"))
mockDB.EXPECT().IsNotFoundError(gomock.Any()).Return(true).AnyTimes()
return newTestNosqlExecutionStore(mockDB, log.NewNoop())
},
testFunc: func(store *nosqlExecutionStore) error {
_, err := store.ListCurrentExecutions(ctx, &persistence.ListCurrentExecutionsRequest{})
return err
},
expectedError: &types.InternalServiceError{Message: "database error"},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
Loading