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

Adding unit tests for RecordActivityTaskHeartbeat #5511

Merged
merged 6 commits into from
Dec 21, 2023
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
55 changes: 54 additions & 1 deletion service/frontend/workflowHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,57 @@ func (s *workflowHandlerSuite) TestStartWorkflowExecution_IsolationGroupDrained(
s.IsType(err, &types.BadRequestError{})
}

func (s *workflowHandlerSuite) TestRecordActivityTaskHeartbeat_Success() {
wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient()))
taskToken := common.TaskToken{
DomainID: s.testDomainID,
WorkflowID: testWorkflowID,
RunID: testRunID,
ActivityID: "1",
}
taskTokenBytes, err := wh.tokenSerializer.Serialize(&taskToken)
s.NoError(err)
req := &types.RecordActivityTaskHeartbeatRequest{
TaskToken: taskTokenBytes,
Details: nil,
Identity: "",
}
resp := &types.RecordActivityTaskHeartbeatResponse{CancelRequested: false}

s.mockDomainCache.EXPECT().GetDomainName(s.testDomainID).Return(s.testDomain, nil)
s.mockHistoryClient.EXPECT().RecordActivityTaskHeartbeat(gomock.Any(),
&types.HistoryRecordActivityTaskHeartbeatRequest{
DomainUUID: s.testDomainID,
HeartbeatRequest: req,
}).Return(resp, nil)

result, err := wh.RecordActivityTaskHeartbeat(context.Background(), req)
s.NoError(err)
s.Equal(resp, result)
}

func (s *workflowHandlerSuite) TestRecordActivityTaskHeartbeat_RequestNotSet() {
wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient()))
result, err := wh.RecordActivityTaskHeartbeat(context.Background(), nil /*request is not set*/)

s.Error(err)
s.Equal(errRequestNotSet, err)
s.Nil(result)
}

func (s *workflowHandlerSuite) TestRecordActivityTaskHeartbeat_TaskTokenNotSet() {
wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient()))
result, err := wh.RecordActivityTaskHeartbeat(context.Background(), &types.RecordActivityTaskHeartbeatRequest{
TaskToken: nil, //task token is not set
Details: nil,
Identity: "",
})

s.Error(err)
s.Equal(errTaskTokenNotSet, err)
s.Nil(result)
}

func (s *workflowHandlerSuite) TestRegisterDomain_Failure_MissingDomainDataKey() {
dynamicClient := dc.NewInMemoryClient()
err := dynamicClient.UpdateValue(dc.RequiredDomainDataKeys, map[string]interface{}{"Tier": true})
Expand Down Expand Up @@ -720,6 +771,7 @@ func (s *workflowHandlerSuite) TestListDomains_Success() {

result, err := wh.ListDomains(context.Background(), &types.ListDomainsRequest{})
s.NoError(err)

s.Equal(2, len(result.GetDomains()))
}

Expand All @@ -736,12 +788,13 @@ func (s *workflowHandlerSuite) TestHealth_StatusOK() {
wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient())) // workflow handler gets initial health status as HealthStatusWarmingUp

result, err := wh.Health(context.Background()) // Health check looks for HealthStatusOK

s.NoError(err)
s.False(result.Ok)

wh.UpdateHealthStatus(HealthStatusOK)

result, err = wh.Health(context.Background())

s.NoError(err)
s.True(result.Ok)
}
Expand Down