Files
tasks/tests/ndc/replication_test.go
YuriandGitHub 12d839ebe1 Functional tests refactoring (#6559)
## What changed?
1. Refactor functional tests.
2. Move all common code into separate module
3. For every test - create designated test suite.
4. For every test - create '_test.go" file that is executing the
corresponding test suite.
5. Lots of minor refactoring related to code being messy.
2024-10-02 16:44:35 -07:00

119 lines
3.8 KiB
Go

// The MIT License
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package ndc
import (
"math"
"reflect"
"time"
"github.com/pborman/uuid"
historypb "go.temporal.io/api/history/v1"
"go.temporal.io/server/common/persistence"
test "go.temporal.io/server/common/testing"
"go.temporal.io/server/service/history/tasks"
"go.temporal.io/server/tests/testcore"
)
func (s *NDCFunctionalTestSuite) TestReplicationMessageDLQ() {
s.T().SkipNow()
var shardID int32 = 1
workflowID := "replication-message-dlq-test" + uuid.New()
runID := uuid.New()
workflowType := "event-generator-workflow-type"
taskqueue := "event-generator-taskQueue"
var historyBatch []*historypb.History
s.generator = test.InitializeHistoryEventGenerator(s.namespace, s.namespaceID, 1)
events := s.generator.GetNextVertices()
historyEvents := &historypb.History{}
for _, event := range events {
historyEvents.Events = append(historyEvents.Events, event.GetData().(*historypb.HistoryEvent))
}
historyBatch = append(historyBatch, historyEvents)
versionHistory := s.eventBatchesToVersionHistory(nil, historyBatch)
s.NotNil(historyBatch)
historyBatch[0].Events[1].Version = 2
s.applyEventsThroughFetcher(
workflowID,
runID,
workflowType,
taskqueue,
versionHistory,
historyBatch,
)
executionManager := s.cluster.ExecutionManager()
expectedDLQMsgs := map[int64]bool{}
for _, batch := range historyBatch {
firstEventID := batch.Events[0].GetEventId()
expectedDLQMsgs[firstEventID] = true
}
// Applying replication messages through fetcher is Async.
// So we need to retry a couple of times.
Loop:
for i := 0; i < 60; i++ {
time.Sleep(time.Second)
actualDLQMsgs := map[int64]bool{}
request := &persistence.GetReplicationTasksFromDLQRequest{
GetHistoryTasksRequest: persistence.GetHistoryTasksRequest{
ShardID: shardID,
TaskCategory: tasks.CategoryReplication,
InclusiveMinTaskKey: tasks.NewImmediateKey(0),
ExclusiveMaxTaskKey: tasks.NewImmediateKey(math.MaxInt64),
BatchSize: math.MaxInt64,
NextPageToken: nil,
},
SourceClusterName: "standby",
}
var token []byte
for doPaging := true; doPaging; doPaging = len(token) > 0 {
request.NextPageToken = token
response, err := executionManager.GetReplicationTasksFromDLQ(testcore.NewContext(), request)
if err != nil {
continue Loop
}
token = response.NextPageToken
for _, task := range response.Tasks {
firstEventID := task.(*tasks.HistoryReplicationTask).FirstEventID
actualDLQMsgs[firstEventID] = true
}
}
if reflect.DeepEqual(expectedDLQMsgs, actualDLQMsgs) {
return
}
}
s.Fail("Failed to get messages from DLQ")
}