From 12abf72ec4099f78510af9affc347e1b3a50f5b0 Mon Sep 17 00:00:00 2001 From: Ding Shun Date: Tue, 15 Feb 2022 18:03:21 +0800 Subject: [PATCH] Fix #4511 * Adapt the UTs --- dm/dm/master/election_test.go | 2 ++ dm/dm/master/etcd.go | 2 +- dm/dm/master/etcd_test.go | 5 ++++- dm/dm/master/openapi_test.go | 3 +++ dm/dm/master/server.go | 2 +- dm/dm/master/server_test.go | 6 +++++- 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/dm/dm/master/election_test.go b/dm/dm/master/election_test.go index ad13d0d4d9b..a521611f0f5 100644 --- a/dm/dm/master/election_test.go +++ b/dm/dm/master/election_test.go @@ -51,6 +51,7 @@ func (t *testElectionSuite) TestFailToStartLeader(c *check.C) { cfg1.Name = "dm-master-1" cfg1.DataDir = c.MkDir() cfg1.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg1.AdvertiseAddr = cfg1.MasterAddr cfg1.PeerUrls = tempurl.Alloc() cfg1.AdvertisePeerUrls = cfg1.PeerUrls cfg1.InitialCluster = fmt.Sprintf("%s=%s", cfg1.Name, cfg1.AdvertisePeerUrls) @@ -68,6 +69,7 @@ func (t *testElectionSuite) TestFailToStartLeader(c *check.C) { cfg2.Name = "dm-master-2" cfg2.DataDir = c.MkDir() cfg2.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg2.AdvertiseAddr = cfg2.MasterAddr cfg2.PeerUrls = tempurl.Alloc() cfg2.AdvertisePeerUrls = cfg2.PeerUrls cfg2.Join = cfg1.MasterAddr // join to an existing cluster diff --git a/dm/dm/master/etcd.go b/dm/dm/master/etcd.go index bd7762cc4b7..a10b53af54b 100644 --- a/dm/dm/master/etcd.go +++ b/dm/dm/master/etcd.go @@ -97,7 +97,7 @@ func prepareJoinEtcd(cfg *Config) error { } // try to join self, invalid - if cfg.Join == cfg.MasterAddr { + if cfg.Join == cfg.AdvertiseAddr { return terror.ErrMasterJoinEmbedEtcdFail.Generate(fmt.Sprintf("join self %s is forbidden", cfg.Join)) } diff --git a/dm/dm/master/etcd_test.go b/dm/dm/master/etcd_test.go index e3a8a8b1572..402396e0e40 100644 --- a/dm/dm/master/etcd_test.go +++ b/dm/dm/master/etcd_test.go @@ -69,7 +69,7 @@ func (t *testEtcdSuite) TestPrepareJoinEtcd(c *check.C) { cfgCluster.Name = "dm-master-1" cfgCluster.DataDir = c.MkDir() cfgCluster.MasterAddr = tempurl.Alloc()[len("http://"):] - cfgCluster.AdvertiseAddr = tempurl.Alloc()[len("http://"):] + cfgCluster.AdvertiseAddr = cfgCluster.MasterAddr cfgCluster.PeerUrls = tempurl.Alloc() c.Assert(cfgCluster.adjust(), check.IsNil) cfgClusterEtcd := genEmbedEtcdConfigWithLogger("info") @@ -79,6 +79,7 @@ func (t *testEtcdSuite) TestPrepareJoinEtcd(c *check.C) { cfgBefore := t.cloneConfig(cfgCluster) // before `prepareJoinEtcd` applied cfgBefore.DataDir = c.MkDir() // overwrite some config items cfgBefore.MasterAddr = tempurl.Alloc()[len("http://"):] + cfgBefore.AdvertiseAddr = cfgBefore.MasterAddr cfgBefore.PeerUrls = tempurl.Alloc() cfgBefore.AdvertisePeerUrls = cfgBefore.PeerUrls c.Assert(cfgBefore.adjust(), check.IsNil) @@ -172,6 +173,7 @@ func (t *testEtcdSuite) TestPrepareJoinEtcd(c *check.C) { cfgAfter2.Name = "dm-master-3" // overwrite some items cfgAfter2.DataDir = c.MkDir() cfgAfter2.MasterAddr = tempurl.Alloc()[len("http://"):] + cfgAfter2.AdvertiseAddr = cfgAfter2.MasterAddr cfgAfter2.PeerUrls = tempurl.Alloc() cfgAfter2.AdvertisePeerUrls = cfgAfter2.PeerUrls err = prepareJoinEtcd(cfgAfter2) @@ -229,6 +231,7 @@ func (t *testEtcdSuite) TestEtcdAutoCompaction(c *check.C) { cfg.DataDir = c.MkDir() cfg.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg.AdvertiseAddr = cfg.MasterAddr cfg.AutoCompactionRetention = "1s" ctx, cancel := context.WithCancel(context.Background()) diff --git a/dm/dm/master/openapi_test.go b/dm/dm/master/openapi_test.go index 453a485bdce..453fee955c1 100644 --- a/dm/dm/master/openapi_test.go +++ b/dm/dm/master/openapi_test.go @@ -85,6 +85,7 @@ func (t *openAPISuite) TestRedirectRequestToLeader(c *check.C) { cfg1.Name = "dm-master-1" cfg1.DataDir = c.MkDir() cfg1.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg1.AdvertiseAddr = cfg1.MasterAddr cfg1.PeerUrls = tempurl.Alloc() cfg1.AdvertisePeerUrls = cfg1.PeerUrls cfg1.InitialCluster = fmt.Sprintf("%s=%s", cfg1.Name, cfg1.AdvertisePeerUrls) @@ -106,6 +107,7 @@ func (t *openAPISuite) TestRedirectRequestToLeader(c *check.C) { cfg2.Name = "dm-master-2" cfg2.DataDir = c.MkDir() cfg2.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg2.AdvertiseAddr = cfg2.MasterAddr cfg2.PeerUrls = tempurl.Alloc() cfg2.AdvertisePeerUrls = cfg2.PeerUrls cfg2.Join = cfg1.MasterAddr // join to an existing cluster @@ -144,6 +146,7 @@ func (t *openAPISuite) TestOpenAPIWillNotStartInDefaultConfig(c *check.C) { cfg1.Name = "dm-master-1" cfg1.DataDir = c.MkDir() cfg1.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg1.AdvertiseAddr = cfg1.MasterAddr cfg1.PeerUrls = tempurl.Alloc() cfg1.AdvertisePeerUrls = cfg1.PeerUrls cfg1.InitialCluster = fmt.Sprintf("%s=%s", cfg1.Name, cfg1.AdvertisePeerUrls) diff --git a/dm/dm/master/server.go b/dm/dm/master/server.go index 365c1a84964..e103d42ece4 100644 --- a/dm/dm/master/server.go +++ b/dm/dm/master/server.go @@ -216,7 +216,7 @@ func (s *Server) Start(ctx context.Context) (err error) { // create an etcd client used in the whole server instance. // NOTE: we only use the local member's address now, but we can use all endpoints of the cluster if needed. - s.etcdClient, err = etcdutil.CreateClient([]string{withHost(s.cfg.MasterAddr)}, tls.TLSConfig()) + s.etcdClient, err = etcdutil.CreateClient([]string{withHost(s.cfg.AdvertiseAddr)}, tls.TLSConfig()) if err != nil { return } diff --git a/dm/dm/master/server_test.go b/dm/dm/master/server_test.go index 1438246ef44..8d23b46fad8 100644 --- a/dm/dm/master/server_test.go +++ b/dm/dm/master/server_test.go @@ -1371,6 +1371,7 @@ func (t *testMaster) TestServer(c *check.C) { cfg.PeerUrls = "http://127.0.0.1:8294" cfg.DataDir = c.MkDir() cfg.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg.AdvertiseAddr = cfg.MasterAddr s := NewServer(cfg) @@ -1594,6 +1595,7 @@ func (t *testMaster) TestJoinMember(c *check.C) { cfg1.Name = "dm-master-1" cfg1.DataDir = c.MkDir() cfg1.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg1.AdvertiseAddr = cfg1.MasterAddr cfg1.PeerUrls = tempurl.Alloc() cfg1.AdvertisePeerUrls = cfg1.PeerUrls cfg1.InitialCluster = fmt.Sprintf("%s=%s", cfg1.Name, cfg1.AdvertisePeerUrls) @@ -1613,6 +1615,7 @@ func (t *testMaster) TestJoinMember(c *check.C) { cfg2.Name = "dm-master-2" cfg2.DataDir = c.MkDir() cfg2.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg2.AdvertiseAddr = cfg2.MasterAddr cfg2.PeerUrls = tempurl.Alloc() cfg2.AdvertisePeerUrls = cfg2.PeerUrls cfg2.Join = cfg1.MasterAddr // join to an existing cluster @@ -1647,6 +1650,7 @@ func (t *testMaster) TestJoinMember(c *check.C) { cfg3.Name = "dm-master-3" cfg3.DataDir = c.MkDir() cfg3.MasterAddr = tempurl.Alloc()[len("http://"):] + cfg3.AdvertiseAddr = cfg3.MasterAddr cfg3.PeerUrls = tempurl.Alloc() cfg3.AdvertisePeerUrls = cfg3.PeerUrls cfg3.Join = cfg1.MasterAddr // join to an existing cluster @@ -1689,7 +1693,7 @@ func (t *testMaster) TestOperateSource(c *check.C) { cfg1.Name = "dm-master-1" cfg1.DataDir = c.MkDir() cfg1.MasterAddr = tempurl.Alloc()[len("http://"):] - cfg1.AdvertiseAddr = tempurl.Alloc()[len("http://"):] + cfg1.AdvertiseAddr = cfg1.MasterAddr cfg1.PeerUrls = tempurl.Alloc() cfg1.AdvertisePeerUrls = cfg1.PeerUrls cfg1.InitialCluster = fmt.Sprintf("%s=%s", cfg1.Name, cfg1.AdvertisePeerUrls)