Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add a new parameter to pass the server name for config #2937

Merged
merged 3 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/client/client_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (s *clientTLSTestSuite) testTLSReload(
useIP bool) {
tlsInfo := cloneFunc()
// 1. start cluster with valid certs
clus, err := tests.NewTestCluster(s.ctx, 1, func(conf *config.Config) {
clus, err := tests.NewTestCluster(s.ctx, 1, func(conf *config.Config, _ string) {
JmPotato marked this conversation as resolved.
Show resolved Hide resolved
conf.Security = grpcutil.SecurityConfig{
KeyPath: tlsInfo.KeyFile,
CertPath: tlsInfo.CertFile,
Expand Down
5 changes: 4 additions & 1 deletion tests/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,10 @@ type TestCluster struct {
}

// ConfigOption is used to define customize settings in test.
type ConfigOption func(conf *config.Config)
// You can use serverName to customize a config for a certain
// server. Usually, the server name will be like `pd1`, `pd2`
// and so on, which determined by the number of servers you set.
type ConfigOption func(conf *config.Config, serverName string)

// NewTestCluster creates a new TestCluster.
func NewTestCluster(ctx context.Context, initialServerCount int, opts ...ConfigOption) (*TestCluster, error) {
Expand Down
2 changes: 1 addition & 1 deletion tests/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (c *serverConfig) Generate(opts ...ConfigOption) (*config.Config, error) {
return nil, err
}
for _, opt := range opts {
opt(cfg)
opt(cfg, c.Name)
}
return cfg, nil
}
Expand Down
2 changes: 1 addition & 1 deletion tests/dashboard/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (s *serverTestSuite) checkServiceIsStopped(c *C, servers map[string]*tests.
}

func (s *serverTestSuite) testDashboard(c *C, internalProxy bool) {
cluster, err := tests.NewTestCluster(s.ctx, 3, func(conf *config.Config) {
cluster, err := tests.NewTestCluster(s.ctx, 3, func(conf *config.Config, _ string) {
conf.Dashboard.InternalProxy = internalProxy
})
c.Assert(err, IsNil)
Expand Down
2 changes: 1 addition & 1 deletion tests/pdctl/label/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *labelTestSuite) SetUpSuite(c *C) {
func (s *labelTestSuite) TestLabel(c *C) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cluster, err := tests.NewTestCluster(ctx, 1, func(cfg *config.Config) { cfg.Replication.StrictlyMatchLabel = false })
cluster, err := tests.NewTestCluster(ctx, 1, func(cfg *config.Config, _ string) { cfg.Replication.StrictlyMatchLabel = false })
c.Assert(err, IsNil)
err = cluster.RunInitialServers()
c.Assert(err, IsNil)
Expand Down
4 changes: 2 additions & 2 deletions tests/pdctl/operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (s *operatorTestSuite) TestOperator(c *C) {
var t time.Time
t = t.Add(time.Hour)
cluster, err := tests.NewTestCluster(ctx, 1,
func(conf *config.Config) { conf.Replication.MaxReplicas = 2 },
func(conf *config.Config) { conf.Schedule.MaxStoreDownTime.Duration = time.Since(t) },
func(conf *config.Config, _ string) { conf.Replication.MaxReplicas = 2 },
func(conf *config.Config, _ string) { conf.Schedule.MaxStoreDownTime.Duration = time.Since(t) },
)
c.Assert(err, IsNil)
err = cluster.RunInitialServers()
Expand Down
4 changes: 2 additions & 2 deletions tests/server/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type serverTestSuite struct{}
func (s *serverTestSuite) TestReconnect(c *C) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cluster, err := tests.NewTestCluster(ctx, 3, func(conf *config.Config) {
cluster, err := tests.NewTestCluster(ctx, 3, func(conf *config.Config, _ string) {
conf.TickInterval = typeutil.Duration{Duration: 50 * time.Millisecond}
conf.ElectionInterval = typeutil.Duration{Duration: 250 * time.Millisecond}
})
Expand Down Expand Up @@ -117,7 +117,7 @@ func (s *testRedirectorSuite) SetUpSuite(c *C) {
ctx, cancel := context.WithCancel(context.Background())
server.EnableZap = true
s.cleanup = cancel
cluster, err := tests.NewTestCluster(ctx, 3, func(conf *config.Config) {
cluster, err := tests.NewTestCluster(ctx, 3, func(conf *config.Config, _ string) {
conf.TickInterval = typeutil.Duration{Duration: 50 * time.Millisecond}
conf.ElectionInterval = typeutil.Duration{Duration: 250 * time.Millisecond}
})
Expand Down
2 changes: 1 addition & 1 deletion tests/server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ func (s *clusterTestSuite) TestTiFlashWithPlacementRules(c *C) {
}

func (s *clusterTestSuite) TestReplicationModeStatus(c *C) {
tc, err := tests.NewTestCluster(s.ctx, 1, func(conf *config.Config) {
tc, err := tests.NewTestCluster(s.ctx, 1, func(conf *config.Config, _ string) {
conf.ReplicationMode.ReplicationMode = "dr-auto-sync"
})

Expand Down
4 changes: 2 additions & 2 deletions tests/server/region_syncer/region_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (i *idAllocator) alloc() uint64 {
}

func (s *serverTestSuite) TestRegionSyncer(c *C) {
cluster, err := tests.NewTestCluster(s.ctx, 3, func(conf *config.Config) { conf.PDServerCfg.UseRegionStorage = true })
cluster, err := tests.NewTestCluster(s.ctx, 3, func(conf *config.Config, _ string) { conf.PDServerCfg.UseRegionStorage = true })
defer cluster.Destroy()
c.Assert(err, IsNil)

Expand Down Expand Up @@ -171,7 +171,7 @@ func (s *serverTestSuite) TestRegionSyncer(c *C) {
}

func (s *serverTestSuite) TestFullSyncWithAddMember(c *C) {
cluster, err := tests.NewTestCluster(s.ctx, 1, func(conf *config.Config) { conf.PDServerCfg.UseRegionStorage = true })
cluster, err := tests.NewTestCluster(s.ctx, 1, func(conf *config.Config, _ string) { conf.PDServerCfg.UseRegionStorage = true })
defer cluster.Destroy()
c.Assert(err, IsNil)

Expand Down
2 changes: 1 addition & 1 deletion tests/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (s *serverTestSuite) TestClusterID(c *C) {
c.Assert(s.GetClusterID(), Equals, clusterID)
}

cluster2, err := tests.NewTestCluster(s.ctx, 3, func(conf *config.Config) { conf.InitialClusterToken = "foobar" })
cluster2, err := tests.NewTestCluster(s.ctx, 3, func(conf *config.Config, _ string) { conf.InitialClusterToken = "foobar" })
defer cluster2.Destroy()
c.Assert(err, IsNil)
err = cluster2.RunInitialServers()
Expand Down
4 changes: 2 additions & 2 deletions tests/server/watch/leader_watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *serverTestSuite) TearDownSuite(c *C) {
}

func (s *serverTestSuite) TestWatcher(c *C) {
cluster, err := tests.NewTestCluster(s.ctx, 1, func(conf *config.Config) { conf.AutoCompactionRetention = "1s" })
cluster, err := tests.NewTestCluster(s.ctx, 1, func(conf *config.Config, _ string) { conf.AutoCompactionRetention = "1s" })
defer cluster.Destroy()
c.Assert(err, IsNil)

Expand Down Expand Up @@ -88,7 +88,7 @@ func (s *serverTestSuite) TestWatcher(c *C) {
}

func (s *serverTestSuite) TestWatcherCompacted(c *C) {
cluster, err := tests.NewTestCluster(s.ctx, 1, func(conf *config.Config) { conf.AutoCompactionRetention = "1s" })
cluster, err := tests.NewTestCluster(s.ctx, 1, func(conf *config.Config, _ string) { conf.AutoCompactionRetention = "1s" })
defer cluster.Destroy()
c.Assert(err, IsNil)

Expand Down