Skip to content

Commit

Permalink
Adding unit tests to RespondActivityTaskCompleted and RecordActivityT… (
Browse files Browse the repository at this point in the history
#5521)

* Adding unit tests to RespondActivityTaskCompleted and RecordActivityTaskHeartbeatByID

* address comments
  • Loading branch information
sankari165 authored Dec 22, 2023
1 parent a31e217 commit f9a80ec
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions service/frontend/workflowHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,89 @@ func (s *workflowHandlerSuite) TestRecordActivityTaskHeartbeat_TaskTokenNotSet()
s.Nil(result)
}

func (s *workflowHandlerSuite) TestRecordActivityTaskHeartbeatByID_Success() {
wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient()))
req := &types.RecordActivityTaskHeartbeatByIDRequest{
Domain: s.testDomain,
WorkflowID: testWorkflowID,
RunID: testRunID,
ActivityID: "1",
}
resp := &types.RecordActivityTaskHeartbeatResponse{CancelRequested: false}

s.mockDomainCache.EXPECT().GetDomainID(s.testDomain).Return(s.testDomainID, nil)
s.mockHistoryClient.EXPECT().RecordActivityTaskHeartbeat(gomock.Any(), gomock.Any()).Return(resp, nil)

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

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

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

func (s *workflowHandlerSuite) TestRecordActivityTaskHeartbeatByID_DomainNotSet() {
wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient()))
result, err := wh.RecordActivityTaskHeartbeatByID(
context.Background(),
&types.RecordActivityTaskHeartbeatByIDRequest{
Domain: "", // domain not set
})

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

func (s *workflowHandlerSuite) TestRespondActivityTaskCompleted_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.RespondActivityTaskCompletedRequest{
TaskToken: taskTokenBytes,
}

s.mockDomainCache.EXPECT().GetDomainName(s.testDomainID).Return(s.testDomain, nil)
s.mockHistoryClient.EXPECT().RespondActivityTaskCompleted(gomock.Any(),
&types.HistoryRespondActivityTaskCompletedRequest{
DomainUUID: taskToken.DomainID,
CompleteRequest: req,
}).Return(nil)

err = wh.RespondActivityTaskCompleted(context.Background(), req)
// only checking for successful write here
s.NoError(err)
}

func (s *workflowHandlerSuite) TestRespondActivityTaskCompletedByID_Success() {
wh := s.getWorkflowHandler(s.newConfig(dc.NewInMemoryClient()))
req := &types.RespondActivityTaskCompletedByIDRequest{
Domain: s.testDomain,
WorkflowID: testWorkflowID,
RunID: testRunID,
ActivityID: "1",
}

s.mockDomainCache.EXPECT().GetDomainID(s.testDomain).Return(s.testDomainID, nil)
s.mockHistoryClient.EXPECT().RespondActivityTaskCompleted(gomock.Any(), gomock.Any()).Return(nil)

err := wh.RespondActivityTaskCompletedByID(context.Background(), req)
// only checking for successful write here
s.NoError(err)
}

func (s *workflowHandlerSuite) TestRegisterDomain_Failure_MissingDomainDataKey() {
dynamicClient := dc.NewInMemoryClient()
err := dynamicClient.UpdateValue(dc.RequiredDomainDataKeys, map[string]interface{}{"Tier": true})
Expand Down

0 comments on commit f9a80ec

Please sign in to comment.