diff --git a/tests/client/client_tls_test.go b/tests/client/client_tls_test.go index 81336dfbb2d..999c9492bfe 100644 --- a/tests/client/client_tls_test.go +++ b/tests/client/client_tls_test.go @@ -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, serverName string) { conf.Security = grpcutil.SecurityConfig{ KeyPath: tlsInfo.KeyFile, CertPath: tlsInfo.CertFile, diff --git a/tests/cluster.go b/tests/cluster.go index 1b314d6d3a9..31e98efdbd3 100644 --- a/tests/cluster.go +++ b/tests/cluster.go @@ -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) { diff --git a/tests/config.go b/tests/config.go index 4c12ce9141b..f32356083c3 100644 --- a/tests/config.go +++ b/tests/config.go @@ -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 } diff --git a/tests/dashboard/service_test.go b/tests/dashboard/service_test.go index 0817bc48060..d3313a7bf11 100644 --- a/tests/dashboard/service_test.go +++ b/tests/dashboard/service_test.go @@ -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, serverName string) { conf.Dashboard.InternalProxy = internalProxy }) c.Assert(err, IsNil) diff --git a/tests/pdctl/label/label_test.go b/tests/pdctl/label/label_test.go index 11a7ca80a8e..1963bc4f75f 100644 --- a/tests/pdctl/label/label_test.go +++ b/tests/pdctl/label/label_test.go @@ -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, serverName string) { cfg.Replication.StrictlyMatchLabel = false }) c.Assert(err, IsNil) err = cluster.RunInitialServers() c.Assert(err, IsNil) diff --git a/tests/pdctl/operator/operator_test.go b/tests/pdctl/operator/operator_test.go index 8a8b75d5d91..a6dd452d110 100644 --- a/tests/pdctl/operator/operator_test.go +++ b/tests/pdctl/operator/operator_test.go @@ -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, serverName string) { conf.Replication.MaxReplicas = 2 }, + func(conf *config.Config, serverName string) { conf.Schedule.MaxStoreDownTime.Duration = time.Since(t) }, ) c.Assert(err, IsNil) err = cluster.RunInitialServers() diff --git a/tests/server/api/api_test.go b/tests/server/api/api_test.go index 8fe18463f98..89ad288521e 100644 --- a/tests/server/api/api_test.go +++ b/tests/server/api/api_test.go @@ -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, serverName string) { conf.TickInterval = typeutil.Duration{Duration: 50 * time.Millisecond} conf.ElectionInterval = typeutil.Duration{Duration: 250 * time.Millisecond} }) @@ -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, serverName string) { conf.TickInterval = typeutil.Duration{Duration: 50 * time.Millisecond} conf.ElectionInterval = typeutil.Duration{Duration: 250 * time.Millisecond} }) diff --git a/tests/server/cluster/cluster_test.go b/tests/server/cluster/cluster_test.go index bd23949c31e..fad64610539 100644 --- a/tests/server/cluster/cluster_test.go +++ b/tests/server/cluster/cluster_test.go @@ -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, serverName string) { conf.ReplicationMode.ReplicationMode = "dr-auto-sync" }) diff --git a/tests/server/region_syncer/region_syncer_test.go b/tests/server/region_syncer/region_syncer_test.go index c75f7182f8c..100245f1bcc 100644 --- a/tests/server/region_syncer/region_syncer_test.go +++ b/tests/server/region_syncer/region_syncer_test.go @@ -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, serverName string) { conf.PDServerCfg.UseRegionStorage = true }) defer cluster.Destroy() c.Assert(err, IsNil) @@ -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, serverName string) { conf.PDServerCfg.UseRegionStorage = true }) defer cluster.Destroy() c.Assert(err, IsNil) diff --git a/tests/server/server_test.go b/tests/server/server_test.go index 6e3c5e75d36..0aebe8e552b 100644 --- a/tests/server/server_test.go +++ b/tests/server/server_test.go @@ -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, serverName string) { conf.InitialClusterToken = "foobar" }) defer cluster2.Destroy() c.Assert(err, IsNil) err = cluster2.RunInitialServers() diff --git a/tests/server/watch/leader_watch_test.go b/tests/server/watch/leader_watch_test.go index 87d8ad01592..5a69a012544 100644 --- a/tests/server/watch/leader_watch_test.go +++ b/tests/server/watch/leader_watch_test.go @@ -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, serverName string) { conf.AutoCompactionRetention = "1s" }) defer cluster.Destroy() c.Assert(err, IsNil) @@ -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, serverName string) { conf.AutoCompactionRetention = "1s" }) defer cluster.Destroy() c.Assert(err, IsNil)