From d6463a14d9adfef63d8e56e3568af08150209663 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Wed, 9 Sep 2020 21:25:46 +0800 Subject: [PATCH 1/2] Add a new parameter to pass the server name for config Signed-off-by: JmPotato --- tests/client/client_tls_test.go | 2 +- tests/cluster.go | 5 ++++- tests/config.go | 2 +- tests/dashboard/service_test.go | 2 +- tests/pdctl/label/label_test.go | 2 +- tests/pdctl/operator/operator_test.go | 4 ++-- tests/server/api/api_test.go | 4 ++-- tests/server/cluster/cluster_test.go | 2 +- tests/server/region_syncer/region_syncer_test.go | 4 ++-- tests/server/server_test.go | 2 +- tests/server/watch/leader_watch_test.go | 4 ++-- 11 files changed, 18 insertions(+), 15 deletions(-) diff --git a/tests/client/client_tls_test.go b/tests/client/client_tls_test.go index 81336dfbb2d..306480fea1e 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, _ 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..5e5c5764176 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, _ 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..5f1ae9ddc37 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, _ 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..7da71e95d37 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, _ string) { conf.Replication.MaxReplicas = 2 }, + func(conf *config.Config, _ 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..3168e7adf79 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, _ 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, _ 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..0d1b40b684f 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, _ 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..6c8a3707e25 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, _ 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, _ 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..c225d01fc16 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, _ 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..c43a78d5640 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, _ 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, _ string) { conf.AutoCompactionRetention = "1s" }) defer cluster.Destroy() c.Assert(err, IsNil) From f8273a788134178e23ea3bf10230aa1b4978c726 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Wed, 9 Sep 2020 21:40:25 +0800 Subject: [PATCH 2/2] Replace _ with a more clear name Signed-off-by: JmPotato --- tests/client/client_tls_test.go | 2 +- tests/dashboard/service_test.go | 2 +- tests/pdctl/label/label_test.go | 2 +- tests/pdctl/operator/operator_test.go | 4 ++-- tests/server/api/api_test.go | 4 ++-- tests/server/cluster/cluster_test.go | 2 +- tests/server/region_syncer/region_syncer_test.go | 4 ++-- tests/server/server_test.go | 2 +- tests/server/watch/leader_watch_test.go | 4 ++-- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/client/client_tls_test.go b/tests/client/client_tls_test.go index 306480fea1e..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, _ string) { + 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/dashboard/service_test.go b/tests/dashboard/service_test.go index 5e5c5764176..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, _ string) { + 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 5f1ae9ddc37..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, _ string) { 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 7da71e95d37..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, _ string) { conf.Replication.MaxReplicas = 2 }, - func(conf *config.Config, _ string) { 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 3168e7adf79..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, _ string) { + 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, _ string) { + 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 0d1b40b684f..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, _ string) { + 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 6c8a3707e25..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, _ string) { 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, _ string) { 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 c225d01fc16..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, _ string) { 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 c43a78d5640..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, _ string) { 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, _ string) { 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)