mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? <!-- Describe what has changed in this PR --> I added an `http_address` field to the `ClusterInformation` struct and related protos. ## Why? <!-- Tell your future self why have you made these changes --> We need this for HTTP request forwarding. ## How did you test it? <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> I added some unit tests. ## Potential risks <!-- Assuming the worst case, what can be broken when deploying this change to production? --> ## Documentation <!-- Have you made sure this change doesn't falsify anything currently stated in `docs/`? If significant new behavior is added, have you described that in `docs/`? --> ## Is hotfix candidate? <!-- Is this PR a hotfix candidate or does it require a notification to be sent to the broader community? (Yes/No) -->
166 lines
6.2 KiB
Go
166 lines
6.2 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.
|
|
|
|
//go:build !race
|
|
|
|
// need to run xdc tests with race detector off because of ringpop bug causing data race issue
|
|
|
|
package xdc
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/suite"
|
|
replicationpb "go.temporal.io/api/replication/v1"
|
|
"go.temporal.io/server/common/testing/historyrequire"
|
|
"gopkg.in/yaml.v3"
|
|
|
|
"go.temporal.io/server/api/adminservice/v1"
|
|
"go.temporal.io/server/common/cluster"
|
|
"go.temporal.io/server/common/dynamicconfig"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/log/tag"
|
|
"go.temporal.io/server/common/testing/protorequire"
|
|
"go.temporal.io/server/environment"
|
|
"go.temporal.io/server/tests"
|
|
)
|
|
|
|
type (
|
|
xdcBaseSuite struct {
|
|
// override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test,
|
|
// not merely log an error
|
|
*require.Assertions
|
|
protorequire.ProtoAssertions
|
|
historyrequire.HistoryRequire
|
|
clusterNames []string
|
|
suite.Suite
|
|
|
|
testClusterFactory tests.TestClusterFactory
|
|
|
|
cluster1 *tests.TestCluster
|
|
cluster2 *tests.TestCluster
|
|
logger log.Logger
|
|
dynamicConfigOverrides map[dynamicconfig.Key]interface{}
|
|
}
|
|
)
|
|
|
|
func (s *xdcBaseSuite) clusterReplicationConfig() []*replicationpb.ClusterReplicationConfig {
|
|
config := make([]*replicationpb.ClusterReplicationConfig, len(s.clusterNames))
|
|
for i, clusterName := range s.clusterNames {
|
|
config[i] = &replicationpb.ClusterReplicationConfig{
|
|
ClusterName: clusterName,
|
|
}
|
|
}
|
|
return config
|
|
}
|
|
|
|
func (s *xdcBaseSuite) setupSuite(clusterNames []string, opts ...tests.Option) {
|
|
s.testClusterFactory = tests.NewTestClusterFactory()
|
|
|
|
params := tests.ApplyTestClusterParams(opts)
|
|
|
|
s.clusterNames = clusterNames
|
|
if s.logger == nil {
|
|
s.logger = log.NewTestLogger()
|
|
}
|
|
if s.dynamicConfigOverrides == nil {
|
|
s.dynamicConfigOverrides = make(map[dynamicconfig.Key]interface{})
|
|
}
|
|
|
|
fileName := "../testdata/xdc_clusters.yaml"
|
|
if tests.TestFlags.TestClusterConfigFile != "" {
|
|
fileName = tests.TestFlags.TestClusterConfigFile
|
|
}
|
|
environment.SetupEnv()
|
|
|
|
confContent, err := os.ReadFile(fileName)
|
|
s.Require().NoError(err)
|
|
confContent = []byte(os.ExpandEnv(string(confContent)))
|
|
|
|
var clusterConfigs []*tests.TestClusterConfig
|
|
s.Require().NoError(yaml.Unmarshal(confContent, &clusterConfigs))
|
|
for i, config := range clusterConfigs {
|
|
config.DynamicConfigOverrides = s.dynamicConfigOverrides
|
|
clusterConfigs[i].ClusterMetadata.MasterClusterName = s.clusterNames[i]
|
|
clusterConfigs[i].ClusterMetadata.CurrentClusterName = s.clusterNames[i]
|
|
clusterConfigs[i].Persistence.DBName = "func_" + s.clusterNames[i]
|
|
clusterConfigs[i].ClusterMetadata.ClusterInformation = make(map[string]cluster.ClusterInformation)
|
|
// TODO: make tests.temporalImpl actually use these ports. Right now, we're just setting these to the values
|
|
// that the tests.temporalImpl uses by default, so that our info here is right, but these aren't actually used
|
|
// by NewCluster.
|
|
clusterConfigs[i].ClusterMetadata.ClusterInformation[s.clusterNames[i]] = cluster.ClusterInformation{
|
|
Enabled: true,
|
|
InitialFailoverVersion: int64(i + 1),
|
|
RPCAddress: fmt.Sprintf("127.0.0.1:%d134", 7+i),
|
|
HTTPAddress: fmt.Sprintf("http://127.0.0.1:%d144", 7+i),
|
|
}
|
|
clusterConfigs[i].ServiceFxOptions = params.ServiceOptions
|
|
}
|
|
|
|
c, err := s.testClusterFactory.NewCluster(s.T(), clusterConfigs[0], log.With(s.logger, tag.ClusterName(s.clusterNames[0])))
|
|
s.Require().NoError(err)
|
|
s.cluster1 = c
|
|
|
|
c, err = s.testClusterFactory.NewCluster(s.T(), clusterConfigs[1], log.With(s.logger, tag.ClusterName(s.clusterNames[1])))
|
|
s.Require().NoError(err)
|
|
s.cluster2 = c
|
|
|
|
cluster1Info := clusterConfigs[0].ClusterMetadata.ClusterInformation[clusterConfigs[0].ClusterMetadata.CurrentClusterName]
|
|
cluster2Info := clusterConfigs[1].ClusterMetadata.ClusterInformation[clusterConfigs[1].ClusterMetadata.CurrentClusterName]
|
|
_, err = s.cluster1.GetAdminClient().AddOrUpdateRemoteCluster(
|
|
tests.NewContext(),
|
|
&adminservice.AddOrUpdateRemoteClusterRequest{
|
|
FrontendAddress: cluster2Info.RPCAddress,
|
|
FrontendHttpAddress: cluster2Info.HTTPAddress,
|
|
EnableRemoteClusterConnection: true,
|
|
})
|
|
s.Require().NoError(err)
|
|
|
|
_, err = s.cluster2.GetAdminClient().AddOrUpdateRemoteCluster(
|
|
tests.NewContext(),
|
|
&adminservice.AddOrUpdateRemoteClusterRequest{
|
|
FrontendAddress: cluster1Info.RPCAddress,
|
|
FrontendHttpAddress: cluster1Info.HTTPAddress,
|
|
EnableRemoteClusterConnection: true,
|
|
})
|
|
s.Require().NoError(err)
|
|
// Wait for cluster metadata to refresh new added clusters
|
|
time.Sleep(time.Millisecond * 200)
|
|
}
|
|
|
|
func (s *xdcBaseSuite) tearDownSuite() {
|
|
s.NoError(s.cluster1.TearDownCluster())
|
|
s.NoError(s.cluster2.TearDownCluster())
|
|
}
|
|
|
|
func (s *xdcBaseSuite) setupTest() {
|
|
// Have to define our overridden assertions in the test setup. If we did it earlier, s.T() will return nil
|
|
s.Assertions = require.New(s.T())
|
|
s.ProtoAssertions = protorequire.New(s.T())
|
|
s.HistoryRequire = historyrequire.New(s.T())
|
|
}
|