mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
167 lines
5.8 KiB
Go
167 lines
5.8 KiB
Go
package history
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/pborman/uuid"
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/suite"
|
|
commonpb "go.temporal.io/api/common/v1"
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
"go.temporal.io/server/api/adminservice/v1"
|
|
enumsspb "go.temporal.io/server/api/enums/v1"
|
|
historyspb "go.temporal.io/server/api/history/v1"
|
|
"go.temporal.io/server/api/historyservice/v1"
|
|
persistencespb "go.temporal.io/server/api/persistence/v1"
|
|
"go.temporal.io/server/common"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/namespace"
|
|
"go.temporal.io/server/common/persistence"
|
|
"go.temporal.io/server/common/persistence/visibility/manager"
|
|
"go.temporal.io/server/service/history/api/forcedeleteworkflowexecution"
|
|
"go.temporal.io/server/service/history/tests"
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
type (
|
|
historyAPISuite struct {
|
|
suite.Suite
|
|
*require.Assertions
|
|
|
|
controller *gomock.Controller
|
|
logger log.Logger
|
|
mockExecutionMgr *persistence.MockExecutionManager
|
|
mockVisibilityMgr *manager.MockVisibilityManager
|
|
mockNamespaceCache *namespace.MockRegistry
|
|
}
|
|
)
|
|
|
|
func TestHistoryAPISuite(t *testing.T) {
|
|
s := new(historyAPISuite)
|
|
suite.Run(t, s)
|
|
}
|
|
|
|
func (s *historyAPISuite) SetupSuite() {
|
|
|
|
}
|
|
|
|
func (s *historyAPISuite) TearDownSuite() {
|
|
}
|
|
|
|
func (s *historyAPISuite) SetupTest() {
|
|
s.Assertions = require.New(s.T())
|
|
|
|
s.controller = gomock.NewController(s.T())
|
|
s.logger = log.NewTestLogger()
|
|
s.mockExecutionMgr = persistence.NewMockExecutionManager(s.controller)
|
|
s.mockVisibilityMgr = manager.NewMockVisibilityManager(s.controller)
|
|
s.mockNamespaceCache = namespace.NewMockRegistry(s.controller)
|
|
s.mockNamespaceCache.EXPECT().GetNamespaceByID(tests.NamespaceID).Return(tests.LocalNamespaceEntry, nil).AnyTimes()
|
|
s.mockNamespaceCache.EXPECT().GetNamespace(tests.Namespace).Return(tests.LocalNamespaceEntry, nil).AnyTimes()
|
|
}
|
|
|
|
func (s *historyAPISuite) TearDownTest() {
|
|
s.controller.Finish()
|
|
}
|
|
func (s *historyAPISuite) TestDeleteWorkflowExecution_DeleteCurrentExecution() {
|
|
execution := commonpb.WorkflowExecution{
|
|
WorkflowId: "workflowID",
|
|
}
|
|
|
|
shardID := common.WorkflowIDToHistoryShard(
|
|
tests.NamespaceID.String(),
|
|
execution.GetWorkflowId(),
|
|
1,
|
|
)
|
|
|
|
request := &historyservice.ForceDeleteWorkflowExecutionRequest{
|
|
NamespaceId: tests.NamespaceID.String(),
|
|
Request: &adminservice.DeleteWorkflowExecutionRequest{
|
|
Execution: &execution,
|
|
},
|
|
}
|
|
|
|
s.mockNamespaceCache.EXPECT().GetNamespaceID(tests.Namespace).Return(tests.NamespaceID, nil).AnyTimes()
|
|
s.mockVisibilityMgr.EXPECT().DeleteWorkflowExecution(gomock.Any(), gomock.Any()).AnyTimes()
|
|
|
|
s.mockExecutionMgr.EXPECT().GetCurrentExecution(gomock.Any(), gomock.Any()).Return(nil, errors.New("some random error"))
|
|
resp, err := forcedeleteworkflowexecution.Invoke(context.Background(), request, shardID, s.mockExecutionMgr, s.mockVisibilityMgr, s.logger)
|
|
s.Nil(resp)
|
|
s.Error(err)
|
|
|
|
mutableState := &persistencespb.WorkflowMutableState{
|
|
ExecutionInfo: &persistencespb.WorkflowExecutionInfo{
|
|
VersionHistories: &historyspb.VersionHistories{
|
|
CurrentVersionHistoryIndex: 0,
|
|
Histories: []*historyspb.VersionHistory{
|
|
{BranchToken: []byte("branch1")},
|
|
{BranchToken: []byte("branch2")},
|
|
{BranchToken: []byte("branch3")},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
runID := uuid.New()
|
|
s.mockExecutionMgr.EXPECT().GetCurrentExecution(gomock.Any(), gomock.Any()).Return(&persistence.GetCurrentExecutionResponse{
|
|
StartRequestID: uuid.New(),
|
|
RunID: runID,
|
|
State: enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED,
|
|
Status: enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
|
|
}, nil)
|
|
s.mockExecutionMgr.EXPECT().GetWorkflowExecution(gomock.Any(), &persistence.GetWorkflowExecutionRequest{
|
|
ShardID: shardID,
|
|
NamespaceID: tests.NamespaceID.String(),
|
|
WorkflowID: execution.WorkflowId,
|
|
RunID: runID,
|
|
}).Return(&persistence.GetWorkflowExecutionResponse{State: mutableState}, nil)
|
|
s.mockExecutionMgr.EXPECT().DeleteCurrentWorkflowExecution(gomock.Any(), &persistence.DeleteCurrentWorkflowExecutionRequest{
|
|
ShardID: shardID,
|
|
NamespaceID: tests.NamespaceID.String(),
|
|
WorkflowID: execution.WorkflowId,
|
|
RunID: runID,
|
|
}).Return(nil)
|
|
s.mockExecutionMgr.EXPECT().DeleteWorkflowExecution(gomock.Any(), &persistence.DeleteWorkflowExecutionRequest{
|
|
ShardID: shardID,
|
|
NamespaceID: tests.NamespaceID.String(),
|
|
WorkflowID: execution.WorkflowId,
|
|
RunID: runID,
|
|
}).Return(nil)
|
|
s.mockExecutionMgr.EXPECT().DeleteHistoryBranch(gomock.Any(), gomock.Any()).Times(len(mutableState.ExecutionInfo.VersionHistories.Histories))
|
|
|
|
_, err = forcedeleteworkflowexecution.Invoke(context.Background(), request, shardID, s.mockExecutionMgr, s.mockVisibilityMgr, s.logger)
|
|
s.NoError(err)
|
|
}
|
|
|
|
func (s *historyAPISuite) TestDeleteWorkflowExecution_LoadMutableStateFailed() {
|
|
execution := commonpb.WorkflowExecution{
|
|
WorkflowId: "workflowID",
|
|
RunId: uuid.New(),
|
|
}
|
|
|
|
shardID := common.WorkflowIDToHistoryShard(
|
|
tests.NamespaceID.String(),
|
|
execution.GetWorkflowId(),
|
|
1,
|
|
)
|
|
|
|
request := &historyservice.ForceDeleteWorkflowExecutionRequest{
|
|
NamespaceId: tests.NamespaceID.String(),
|
|
Request: &adminservice.DeleteWorkflowExecutionRequest{
|
|
Execution: &execution,
|
|
},
|
|
}
|
|
|
|
s.mockNamespaceCache.EXPECT().GetNamespaceID(tests.Namespace).Return(tests.NamespaceID, nil).AnyTimes()
|
|
s.mockVisibilityMgr.EXPECT().DeleteWorkflowExecution(gomock.Any(), gomock.Any()).AnyTimes()
|
|
|
|
s.mockExecutionMgr.EXPECT().GetWorkflowExecution(gomock.Any(), gomock.Any()).Return(nil, errors.New("some random error"))
|
|
s.mockExecutionMgr.EXPECT().DeleteCurrentWorkflowExecution(gomock.Any(), gomock.Any()).Return(nil)
|
|
s.mockExecutionMgr.EXPECT().DeleteWorkflowExecution(gomock.Any(), gomock.Any()).Return(nil)
|
|
|
|
_, err := forcedeleteworkflowexecution.Invoke(context.Background(), request, shardID, s.mockExecutionMgr, s.mockVisibilityMgr, s.logger)
|
|
s.NoError(err)
|
|
}
|