Skip to content

Commit

Permalink
integration: ensure 'StopNotify' on publish error
Browse files Browse the repository at this point in the history
Signed-off-by: Gyu-Ho Lee <[email protected]>
  • Loading branch information
gyuho committed Mar 20, 2017
1 parent 543800a commit 7532413
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
8 changes: 6 additions & 2 deletions integration/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ type member struct {

// serverClient is a clientv3 that directly calls the etcdserver.
serverClient *clientv3.Client

keepDataDirStop bool
}

func (m *member) GRPCAddr() string { return m.grpcAddr }
Expand Down Expand Up @@ -769,8 +771,10 @@ func (m *member) Restart(t *testing.T) error {
func (m *member) Terminate(t *testing.T) {
plog.Printf("terminating %s (%s)", m.Name, m.grpcAddr)
m.Close()
if err := os.RemoveAll(m.ServerConfig.DataDir); err != nil {
t.Fatal(err)
if !m.keepDataDirStop {
if err := os.RemoveAll(m.ServerConfig.DataDir); err != nil {
t.Fatal(err)
}
}
plog.Printf("terminated %s (%s)", m.Name, m.grpcAddr)
}
Expand Down
44 changes: 44 additions & 0 deletions integration/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,50 @@ func TestRejectUnhealthyRemove(t *testing.T) {
}
}

// TestRestartRemoved ensures that restarting removed member must exit
// if 'initial-cluster-state' is set 'new' and old data directory still exists
// (see https://github.com/coreos/etcd/issues/7512 for more).
func TestRestartRemoved(t *testing.T) {
defer testutil.AfterTest(t)

// 1. start single-member cluster
c := NewCluster(t, 1)
for _, m := range c.Members {
m.ServerConfig.StrictReconfigCheck = true
}
c.Launch(t)
defer c.Terminate(t)

// 2. add a new member
c.AddMember(t)
c.WaitLeader(t)

oldm := c.Members[0]
oldm.keepDataDirStop = true

// 3. remove first member, shut down without deleting data
if err := c.removeMember(t, uint64(c.Members[0].s.ID())); err != nil {
t.Fatalf("expected to remove member, got error %v", err)
}
c.WaitLeader(t)

// 4. restart first member with 'initial-cluster-state=new'
// wrong config, expects exit within ReqTimeout
oldm.ServerConfig.NewCluster = false
if err := oldm.Restart(t); err != nil {
t.Fatalf("unexpected ForceRestart error: %v", err)
}
defer func() {
oldm.Close()
os.RemoveAll(oldm.ServerConfig.DataDir)
}()
select {
case <-oldm.s.StopNotify():
case <-time.After(30 * time.Second):
t.Fatalf("removed member didn't return after %v", 30*time.Second)
}
}

// clusterMustProgress ensures that cluster can make progress. It creates
// a random key first, and check the new key could be got from all client urls
// of the cluster.
Expand Down

0 comments on commit 7532413

Please sign in to comment.