mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-30 14:56:19 +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`.
179 lines
5.7 KiB
Go
179 lines
5.7 KiB
Go
package workflow
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/suite"
|
|
"go.temporal.io/api/serviceerror"
|
|
persistencespb "go.temporal.io/server/api/persistence/v1"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/namespace"
|
|
"go.temporal.io/server/common/persistence"
|
|
"go.temporal.io/server/common/util"
|
|
historyi "go.temporal.io/server/service/history/interfaces"
|
|
"go.temporal.io/server/service/history/tests"
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
type (
|
|
transactionSuite struct {
|
|
suite.Suite
|
|
*require.Assertions
|
|
|
|
controller *gomock.Controller
|
|
mockShard *historyi.MockShardContext
|
|
mockEngine *historyi.MockEngine
|
|
mockNamespaceCache *namespace.MockRegistry
|
|
|
|
logger log.Logger
|
|
|
|
transaction *TransactionImpl
|
|
}
|
|
)
|
|
|
|
func TestTransactionSuite(t *testing.T) {
|
|
s := new(transactionSuite)
|
|
suite.Run(t, s)
|
|
}
|
|
|
|
func (s *transactionSuite) SetupTest() {
|
|
s.Assertions = require.New(s.T())
|
|
|
|
s.controller = gomock.NewController(s.T())
|
|
s.mockShard = historyi.NewMockShardContext(s.controller)
|
|
s.mockEngine = historyi.NewMockEngine(s.controller)
|
|
s.mockNamespaceCache = namespace.NewMockRegistry(s.controller)
|
|
s.logger = log.NewTestLogger()
|
|
|
|
s.mockShard.EXPECT().GetShardID().Return(int32(1)).AnyTimes()
|
|
s.mockShard.EXPECT().GetEngine(gomock.Any()).Return(s.mockEngine, nil).AnyTimes()
|
|
s.mockShard.EXPECT().GetNamespaceRegistry().Return(s.mockNamespaceCache).AnyTimes()
|
|
s.mockShard.EXPECT().GetLogger().Return(s.logger).AnyTimes()
|
|
s.mockNamespaceCache.EXPECT().GetNamespaceByID(tests.NamespaceID).Return(tests.GlobalNamespaceEntry, nil).AnyTimes()
|
|
|
|
s.transaction = NewTransaction(s.mockShard)
|
|
}
|
|
|
|
func (s *transactionSuite) TearDownTest() {
|
|
s.controller.Finish()
|
|
}
|
|
|
|
func (s *transactionSuite) TestOperationMayApplied() {
|
|
testCases := []struct {
|
|
err error
|
|
mayApplied bool
|
|
}{
|
|
{err: &persistence.CurrentWorkflowConditionFailedError{}, mayApplied: false},
|
|
{err: &persistence.WorkflowConditionFailedError{}, mayApplied: false},
|
|
{err: &persistence.ConditionFailedError{}, mayApplied: false},
|
|
{err: &persistence.ShardOwnershipLostError{}, mayApplied: false},
|
|
{err: &persistence.InvalidPersistenceRequestError{}, mayApplied: false},
|
|
{err: &persistence.TransactionSizeLimitError{}, mayApplied: false},
|
|
{err: &serviceerror.ResourceExhausted{}, mayApplied: false},
|
|
{err: &serviceerror.NotFound{}, mayApplied: false},
|
|
{err: &serviceerror.NamespaceNotFound{}, mayApplied: false},
|
|
{err: nil, mayApplied: true},
|
|
{err: &persistence.TimeoutError{}, mayApplied: true},
|
|
{err: &serviceerror.Unavailable{}, mayApplied: true},
|
|
{err: errors.New("some unknown error"), mayApplied: true},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
s.Equal(tc.mayApplied, persistence.OperationPossiblySucceeded(tc.err))
|
|
}
|
|
}
|
|
|
|
func (s *transactionSuite) TestCreateWorkflowExecution_NotifyTaskWhenFailed() {
|
|
timeoutErr := &persistence.TimeoutError{}
|
|
s.True(persistence.OperationPossiblySucceeded(timeoutErr))
|
|
|
|
s.mockShard.EXPECT().CreateWorkflowExecution(gomock.Any(), gomock.Any()).Return(nil, timeoutErr)
|
|
s.setupMockForTaskNotification()
|
|
|
|
_, err := s.transaction.CreateWorkflowExecution(
|
|
context.Background(),
|
|
persistence.CreateWorkflowModeBrandNew,
|
|
0,
|
|
&persistence.WorkflowSnapshot{
|
|
ExecutionInfo: &persistencespb.WorkflowExecutionInfo{
|
|
NamespaceId: tests.NamespaceID.String(),
|
|
WorkflowId: tests.WorkflowID,
|
|
},
|
|
ExecutionState: &persistencespb.WorkflowExecutionState{
|
|
RunId: tests.RunID,
|
|
},
|
|
},
|
|
[]*persistence.WorkflowEvents{},
|
|
)
|
|
s.Equal(timeoutErr, err)
|
|
}
|
|
|
|
func (s *transactionSuite) TestUpdateWorkflowExecution_NotifyTaskWhenFailed() {
|
|
timeoutErr := &persistence.TimeoutError{}
|
|
s.True(persistence.OperationPossiblySucceeded(timeoutErr))
|
|
|
|
s.mockShard.EXPECT().UpdateWorkflowExecution(gomock.Any(), gomock.Any()).Return(nil, timeoutErr)
|
|
s.setupMockForTaskNotification() // for current workflow mutation
|
|
s.setupMockForTaskNotification() // for new workflow snapshot
|
|
|
|
_, _, err := s.transaction.UpdateWorkflowExecution(
|
|
context.Background(),
|
|
persistence.UpdateWorkflowModeUpdateCurrent,
|
|
0,
|
|
&persistence.WorkflowMutation{
|
|
ExecutionInfo: &persistencespb.WorkflowExecutionInfo{
|
|
NamespaceId: tests.NamespaceID.String(),
|
|
WorkflowId: tests.WorkflowID,
|
|
},
|
|
ExecutionState: &persistencespb.WorkflowExecutionState{
|
|
RunId: tests.RunID,
|
|
},
|
|
},
|
|
[]*persistence.WorkflowEvents{},
|
|
util.Ptr(int64(0)),
|
|
&persistence.WorkflowSnapshot{},
|
|
[]*persistence.WorkflowEvents{},
|
|
)
|
|
s.Equal(timeoutErr, err)
|
|
}
|
|
|
|
func (s *transactionSuite) TestConflictResolveWorkflowExecution_NotifyTaskWhenFailed() {
|
|
timeoutErr := &persistence.TimeoutError{}
|
|
s.True(persistence.OperationPossiblySucceeded(timeoutErr))
|
|
|
|
s.mockShard.EXPECT().ConflictResolveWorkflowExecution(gomock.Any(), gomock.Any()).Return(nil, timeoutErr)
|
|
s.setupMockForTaskNotification() // for reset workflow snapshot
|
|
s.setupMockForTaskNotification() // for new workflow snapshot
|
|
s.setupMockForTaskNotification() // for current workflow mutation
|
|
|
|
_, _, _, err := s.transaction.ConflictResolveWorkflowExecution(
|
|
context.Background(),
|
|
persistence.ConflictResolveWorkflowModeUpdateCurrent,
|
|
0,
|
|
&persistence.WorkflowSnapshot{
|
|
ExecutionInfo: &persistencespb.WorkflowExecutionInfo{
|
|
NamespaceId: tests.NamespaceID.String(),
|
|
WorkflowId: tests.WorkflowID,
|
|
},
|
|
ExecutionState: &persistencespb.WorkflowExecutionState{
|
|
RunId: tests.RunID,
|
|
},
|
|
},
|
|
[]*persistence.WorkflowEvents{},
|
|
util.Ptr(int64(0)),
|
|
&persistence.WorkflowSnapshot{},
|
|
[]*persistence.WorkflowEvents{},
|
|
util.Ptr(int64(0)),
|
|
&persistence.WorkflowMutation{},
|
|
[]*persistence.WorkflowEvents{},
|
|
)
|
|
s.Equal(timeoutErr, err)
|
|
}
|
|
|
|
func (s *transactionSuite) setupMockForTaskNotification() {
|
|
s.mockEngine.EXPECT().NotifyNewTasks(gomock.Any()).Times(1)
|
|
}
|