Skip to content

Commit

Permalink
Adding unit tests for RecordActivityTaskHeartbeat (cadence-workflow#5511
Browse files Browse the repository at this point in the history
)

* Adding unit tests to workflowHandler_test.go

* Adding unit tests for RecordActivityTaskHeartbeat
  • Loading branch information
sankari165 authored Dec 21, 2023
1 parent 1ef976b commit da9bdf7
Showing 1 changed file with 54 additions and 1 deletion.
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

0 comments on commit da9bdf7

Please sign in to comment.