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`.
279 lines
4.7 KiB
Go
279 lines
4.7 KiB
Go
package ndc
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/pborman/uuid"
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/suite"
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
historypb "go.temporal.io/api/history/v1"
|
|
"go.temporal.io/server/common/cluster"
|
|
"go.temporal.io/server/common/definition"
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
type (
|
|
replicationTaskSuite struct {
|
|
suite.Suite
|
|
*require.Assertions
|
|
|
|
controller *gomock.Controller
|
|
clusterMetadata *cluster.MockMetadata
|
|
}
|
|
)
|
|
|
|
func TestReplicationTaskSuite(t *testing.T) {
|
|
s := new(replicationTaskSuite)
|
|
suite.Run(t, s)
|
|
}
|
|
|
|
func (s *replicationTaskSuite) SetupSuite() {
|
|
s.Assertions = require.New(s.T())
|
|
s.controller = gomock.NewController(s.T())
|
|
s.clusterMetadata = cluster.NewMockMetadata(s.controller)
|
|
s.clusterMetadata.EXPECT().ClusterNameForFailoverVersion(gomock.Any(), gomock.Any()).Return("some random cluster name").AnyTimes()
|
|
}
|
|
|
|
func (s *replicationTaskSuite) TearDownSuite() {
|
|
|
|
}
|
|
|
|
func (s *replicationTaskSuite) TestValidateEventsSlice() {
|
|
eS1 := []*historypb.HistoryEvent{
|
|
{
|
|
EventId: 1,
|
|
Version: 2,
|
|
},
|
|
{
|
|
EventId: 2,
|
|
Version: 2,
|
|
},
|
|
}
|
|
eS2 := []*historypb.HistoryEvent{
|
|
{
|
|
EventId: 3,
|
|
Version: 2,
|
|
},
|
|
}
|
|
|
|
eS3 := []*historypb.HistoryEvent{
|
|
{
|
|
EventId: 4,
|
|
Version: 2,
|
|
},
|
|
}
|
|
|
|
v, err := validateEventsSlice(eS1, eS2)
|
|
s.Equal(int64(2), v)
|
|
s.Nil(err)
|
|
|
|
v, err = validateEventsSlice(eS1, eS3)
|
|
s.Equal(int64(0), v)
|
|
s.IsType(ErrEventSlicesNotConsecutive, err)
|
|
|
|
v, err = validateEventsSlice(eS1, nil)
|
|
s.Equal(int64(0), v)
|
|
s.IsType(ErrEmptyEventSlice, err)
|
|
}
|
|
|
|
func (s *replicationTaskSuite) TestValidateEvents() {
|
|
eS1 := []*historypb.HistoryEvent{
|
|
{
|
|
EventId: 1,
|
|
Version: 2,
|
|
},
|
|
{
|
|
EventId: 2,
|
|
Version: 2,
|
|
},
|
|
}
|
|
|
|
eS2 := []*historypb.HistoryEvent{
|
|
{
|
|
EventId: 1,
|
|
Version: 2,
|
|
},
|
|
{
|
|
EventId: 3,
|
|
Version: 2,
|
|
},
|
|
}
|
|
|
|
eS3 := []*historypb.HistoryEvent{
|
|
{
|
|
EventId: 1,
|
|
Version: 1,
|
|
},
|
|
{
|
|
EventId: 2,
|
|
Version: 2,
|
|
},
|
|
}
|
|
|
|
v, err := validateEvents(eS1)
|
|
s.Nil(err)
|
|
s.Equal(int64(2), v)
|
|
|
|
v, err = validateEvents(eS2)
|
|
s.Equal(int64(0), v)
|
|
s.IsType(ErrEventIDMismatch, err)
|
|
|
|
v, err = validateEvents(eS3)
|
|
s.Equal(int64(0), v)
|
|
s.IsType(ErrEventVersionMismatch, err)
|
|
}
|
|
|
|
func (s *replicationTaskSuite) TestSkipDuplicatedEvents_ValidInput_SkipEvents() {
|
|
workflowKey := definition.WorkflowKey{
|
|
WorkflowID: uuid.New(),
|
|
RunID: uuid.New(),
|
|
}
|
|
slice1 := []*historypb.HistoryEvent{
|
|
{
|
|
EventId: 11,
|
|
},
|
|
{
|
|
EventId: 12,
|
|
},
|
|
}
|
|
slice2 := []*historypb.HistoryEvent{
|
|
{
|
|
EventId: 13,
|
|
},
|
|
{
|
|
EventId: 14,
|
|
},
|
|
}
|
|
|
|
task, _ := newReplicationTask(
|
|
s.clusterMetadata,
|
|
nil,
|
|
workflowKey,
|
|
nil,
|
|
nil,
|
|
[][]*historypb.HistoryEvent{slice1, slice2},
|
|
nil,
|
|
"",
|
|
nil,
|
|
false,
|
|
)
|
|
err := task.skipDuplicatedEvents(1)
|
|
s.NoError(err)
|
|
s.Equal(1, len(task.getEvents()))
|
|
s.Equal(slice2, task.getEvents()[0])
|
|
s.Equal(int64(13), task.getFirstEvent().EventId)
|
|
s.Equal(int64(14), task.getLastEvent().EventId)
|
|
}
|
|
|
|
func (s *replicationTaskSuite) TestSkipDuplicatedEvents_InvalidInput_ErrorOut() {
|
|
workflowKey := definition.WorkflowKey{
|
|
WorkflowID: uuid.New(),
|
|
RunID: uuid.New(),
|
|
}
|
|
slice1 := []*historypb.HistoryEvent{
|
|
{
|
|
EventId: 11,
|
|
},
|
|
{
|
|
EventId: 12,
|
|
},
|
|
}
|
|
slice2 := []*historypb.HistoryEvent{
|
|
{
|
|
EventId: 13,
|
|
},
|
|
{
|
|
EventId: 14,
|
|
},
|
|
}
|
|
|
|
task, _ := newReplicationTask(
|
|
s.clusterMetadata,
|
|
nil,
|
|
workflowKey,
|
|
nil,
|
|
nil,
|
|
[][]*historypb.HistoryEvent{slice1, slice2},
|
|
nil,
|
|
"",
|
|
nil,
|
|
false,
|
|
)
|
|
err := task.skipDuplicatedEvents(2)
|
|
s.Error(err)
|
|
}
|
|
|
|
func (s *replicationTaskSuite) TestSkipDuplicatedEvents_ZeroInput_DoNothing() {
|
|
workflowKey := definition.WorkflowKey{
|
|
WorkflowID: uuid.New(),
|
|
RunID: uuid.New(),
|
|
}
|
|
slice1 := []*historypb.HistoryEvent{
|
|
{
|
|
EventId: 11,
|
|
},
|
|
{
|
|
EventId: 12,
|
|
},
|
|
}
|
|
slice2 := []*historypb.HistoryEvent{
|
|
{
|
|
EventId: 13,
|
|
},
|
|
{
|
|
EventId: 14,
|
|
},
|
|
}
|
|
|
|
task, _ := newReplicationTask(
|
|
s.clusterMetadata,
|
|
nil,
|
|
workflowKey,
|
|
nil,
|
|
nil,
|
|
[][]*historypb.HistoryEvent{slice1, slice2},
|
|
nil,
|
|
"",
|
|
nil,
|
|
false,
|
|
)
|
|
err := task.skipDuplicatedEvents(0)
|
|
s.NoError(err)
|
|
s.Equal(2, len(task.getEvents()))
|
|
s.Equal(slice1, task.getEvents()[0])
|
|
s.Equal(slice2, task.getEvents()[1])
|
|
}
|
|
|
|
func (s *replicationTaskSuite) TestResetInfo() {
|
|
workflowKey := definition.WorkflowKey{
|
|
WorkflowID: uuid.New(),
|
|
RunID: uuid.New(),
|
|
}
|
|
slice1 := []*historypb.HistoryEvent{
|
|
{
|
|
EventId: 13,
|
|
EventType: enumspb.EVENT_TYPE_WORKFLOW_TASK_FAILED,
|
|
},
|
|
{
|
|
EventId: 14,
|
|
},
|
|
}
|
|
|
|
task, _ := newReplicationTask(
|
|
s.clusterMetadata,
|
|
nil,
|
|
workflowKey,
|
|
nil,
|
|
nil,
|
|
[][]*historypb.HistoryEvent{slice1},
|
|
nil,
|
|
"",
|
|
nil,
|
|
false,
|
|
)
|
|
info := task.getBaseWorkflowInfo()
|
|
s.Nil(info)
|
|
s.False(task.isWorkflowReset())
|
|
}
|