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 missing tests for metered.go #6086

Merged
merged 1 commit into from
Jun 3, 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
206 changes: 204 additions & 2 deletions service/frontend/wrappers/metered/metered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ func TestSignalMetricHasSignalName(t *testing.T) {
signalRequest := &types.SignalWorkflowExecutionRequest{
SignalName: "test_signal",
}
handler.SignalWorkflowExecution(context.Background(), signalRequest)
err := handler.SignalWorkflowExecution(context.Background(), signalRequest)
if err != nil {
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean to return here on error or assert no err?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my copilot added this accidentally via that handle error thing. removing.

}

expectedMetrics := make(map[string]bool)
expectedMetrics["test.cadence_requests"] = false
Expand Down Expand Up @@ -105,7 +108,6 @@ func TestHandleErr_InternalServiceError(t *testing.T) {

assert.NotNil(t, err)
assert.Contains(t, err.Error(), "cadence internal error")
assert.Contains(t, err.Error(), "internal error")
}

func TestHandleErr_UncategorizedError(t *testing.T) {
Expand Down Expand Up @@ -543,3 +545,203 @@ func TestToPollForDecisionTaskRequestTags(t *testing.T) {

assert.ElementsMatch(t, expectedTags, tags)
}

func TestToListWorkflowExecutionsRequestTags(t *testing.T) {
req := &types.ListWorkflowExecutionsRequest{
Domain: "test-domain",
}

tags := toListWorkflowExecutionsRequestTags(req)

expectedTags := []tag.Tag{
tag.WorkflowDomainName("test-domain"),
}

assert.ElementsMatch(t, expectedTags, tags)
}

func TestToPollForActivityTaskRequestTags(t *testing.T) {
kind := types.TaskListKindNormal
req := &types.PollForActivityTaskRequest{
Domain: "test-domain",
TaskList: &types.TaskList{
Name: "test-task-list",
Kind: &kind,
},
}

tags := toPollForActivityTaskRequestTags(req)

expectedTags := []tag.Tag{
tag.WorkflowDomainName("test-domain"),
tag.WorkflowTaskListName("test-task-list"),
tag.WorkflowTaskListKind(int32(types.TaskListKindNormal)),
}

assert.ElementsMatch(t, expectedTags, tags)
}

func TestToSignalWithStartWorkflowExecutionAsyncRequestTags(t *testing.T) {
req := &types.SignalWithStartWorkflowExecutionAsyncRequest{
SignalWithStartWorkflowExecutionRequest: &types.SignalWithStartWorkflowExecutionRequest{
Domain: "test-domain",
WorkflowID: "test-workflow-id",
WorkflowType: &types.WorkflowType{
Name: "test-workflow-type",
},
SignalName: "test-signal",
},
}

tags := toSignalWithStartWorkflowExecutionAsyncRequestTags(req)

expectedTags := []tag.Tag{
tag.WorkflowDomainName("test-domain"),
tag.WorkflowID("test-workflow-id"),
tag.WorkflowType("test-workflow-type"),
tag.WorkflowSignalName("test-signal"),
}

assert.ElementsMatch(t, expectedTags, tags)
}

func TestToDescribeTaskListRequestTags(t *testing.T) {
kind := types.TaskListKindNormal
taskListType := types.TaskListTypeDecision
req := &types.DescribeTaskListRequest{
Domain: "test-domain",
TaskList: &types.TaskList{
Name: "test-task-list",
Kind: &kind,
},
TaskListType: &taskListType,
}

tags := toDescribeTaskListRequestTags(req)

expectedTags := []tag.Tag{
tag.WorkflowDomainName("test-domain"),
tag.WorkflowTaskListName("test-task-list"),
tag.WorkflowTaskListType(int(taskListType)),
tag.WorkflowTaskListKind(int32(types.TaskListKindNormal)),
}

assert.ElementsMatch(t, expectedTags, tags)
}

func TestHandleErr(t *testing.T) {
tests := []struct {
name string
err error
expectedErrType interface{}
expectedErrMsg string
expectedCounter string
}{
{
name: "BadRequestError",
err: &types.BadRequestError{Message: "bad request"},
expectedErrType: &types.BadRequestError{},
expectedErrMsg: "bad request",
expectedCounter: "test.cadence_err_bad_request_counter+",
},
{
name: "DomainNotActiveError",
err: &types.DomainNotActiveError{Message: "domain not active"},
expectedErrType: &types.DomainNotActiveError{},
expectedErrMsg: "domain not active",
expectedCounter: "test.cadence_err_bad_request_counter+",
},
{
name: "ServiceBusyError",
err: &types.ServiceBusyError{Message: "service busy"},
expectedErrType: &types.ServiceBusyError{},
expectedErrMsg: "service busy",
expectedCounter: "test.cadence_err_service_busy_counter+",
},
{
name: "EntityNotExistsError",
err: &types.EntityNotExistsError{Message: "entity not exists"},
expectedErrType: &types.EntityNotExistsError{},
expectedErrMsg: "entity not exists",
expectedCounter: "test.cadence_err_entity_not_exists_counter+",
},
{
name: "WorkflowExecutionAlreadyCompletedError",
err: &types.WorkflowExecutionAlreadyCompletedError{Message: "workflow execution already completed"},
expectedErrType: &types.WorkflowExecutionAlreadyCompletedError{},
expectedErrMsg: "workflow execution already completed",
expectedCounter: "test.cadence_err_workflow_execution_already_completed_counter+",
},
{
name: "WorkflowExecutionAlreadyStartedError",
err: &types.WorkflowExecutionAlreadyStartedError{Message: "workflow execution already started"},
expectedErrType: &types.WorkflowExecutionAlreadyStartedError{},
expectedErrMsg: "workflow execution already started",
expectedCounter: "test.cadence_err_execution_already_started_counter+",
},
{
name: "DomainAlreadyExistsError",
err: &types.DomainAlreadyExistsError{Message: "domain already exists"},
expectedErrType: &types.DomainAlreadyExistsError{},
expectedErrMsg: "domain already exists",
expectedCounter: "test.cadence_err_domain_already_exists_counter+",
},
{
name: "CancellationAlreadyRequestedError",
err: &types.CancellationAlreadyRequestedError{Message: "cancellation already requested"},
expectedErrType: &types.CancellationAlreadyRequestedError{},
expectedErrMsg: "cancellation already requested",
expectedCounter: "test.cadence_err_cancellation_already_requested_counter+",
},
{
name: "QueryFailedError",
err: &types.QueryFailedError{Message: "query failed"},
expectedErrType: &types.QueryFailedError{},
expectedErrMsg: "query failed",
expectedCounter: "test.cadence_err_query_failed_counter+",
},
{
name: "LimitExceededError",
err: &types.LimitExceededError{Message: "limit exceeded"},
expectedErrType: &types.LimitExceededError{},
expectedErrMsg: "limit exceeded",
expectedCounter: "test.cadence_err_limit_exceeded_counter+",
},
{
name: "ClientVersionNotSupportedError",
err: &types.ClientVersionNotSupportedError{},
expectedErrType: &types.ClientVersionNotSupportedError{},
expectedErrMsg: "client version not supported",
expectedCounter: "test.cadence_err_client_version_not_supported_counter+",
},
{
name: "ContextDeadlineExceeded",
err: context.DeadlineExceeded,
expectedErrType: context.DeadlineExceeded,
expectedErrMsg: "context deadline exceeded",
expectedCounter: "test.cadence_err_context_timeout_counter+",
},
{
name: "UncategorizedError",
err: errors.New("unknown error"),
expectedErrType: errors.New("unknown error"),
expectedErrMsg: "unknown error",
expectedCounter: "test.cadence_failures+",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
logger := testlogger.New(t)
testScope := tally.NewTestScope("test", nil)
metricsClient := metrics.NewClient(testScope, metrics.Frontend)
handler := &apiHandler{}

err := handler.handleErr(tt.err, metricsClient.Scope(0), logger)

assert.NotNil(t, err)
assert.IsType(t, tt.expectedErrType, err)
assert.Contains(t, err.Error(), tt.expectedErrMsg)
})
}
}
Loading