Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Adapt the UTs
  • Loading branch information
dsdashun authored and ti-chi-bot committed Feb 21, 2022
1 parent efeedfd commit c5b44ea
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions dm/dm/master/election_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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)
Expand All @@ -60,6 +61,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
Expand Down
2 changes: 1 addition & 1 deletion dm/dm/master/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
5 changes: 4 additions & 1 deletion dm/dm/master/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 3 additions & 0 deletions dm/dm/master/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -105,6 +106,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
Expand Down Expand Up @@ -138,6 +140,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)
Expand Down
2 changes: 1 addition & 1 deletion dm/dm/master/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,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
}
Expand Down
6 changes: 5 additions & 1 deletion dm/dm/master/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,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)

Expand Down Expand Up @@ -1534,6 +1535,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)
Expand All @@ -1553,6 +1555,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
Expand Down Expand Up @@ -1587,6 +1590,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
Expand Down Expand Up @@ -1629,7 +1633,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)
Expand Down

0 comments on commit c5b44ea

Please sign in to comment.