Parcourir la source

server: add testCluster.Add

and fix possible testing error.
Yicheng Qin il y a 11 ans
Parent
commit
f7417cf693
2 fichiers modifiés avec 19 ajouts et 8 suppressions
  1. 2 4
      etcd/etcd_start_test.go
  2. 17 4
      etcd/etcd_test.go

+ 2 - 4
etcd/etcd_start_test.go

@@ -151,11 +151,9 @@ func TestRunByDiscoveryService(t *testing.T) {
 	c := newTestConfig()
 	c.Name = bootstrapName
 	c.Discovery = ds.URL(0) + "/v2/keys/_etcd/registry/1"
-	ts := testServer{Config: c}
-	ts.Start()
-	defer ts.Destroy()
+	ts := &testServer{Config: c}
+	ds.Add(ts)
 
-	ts.WaitMode(participantMode)
 	// wait for the leader to do a heartbeat
 	// it will update the lead field of the follower
 	time.Sleep(ds.Node(0).e.tickDuration * defaultHeartbeat * 2)

+ 17 - 4
etcd/etcd_test.go

@@ -250,10 +250,8 @@ func TestRestoreSnapshotFromLeader(t *testing.T) {
 	c := newTestConfig()
 	c.Name = "1"
 	c.Peers = []string{cl.URL(0)}
-	ts := testServer{Config: c}
-	ts.Start()
-	defer ts.Destroy()
-	ts.WaitMode(participantMode)
+	ts := &testServer{Config: c}
+	cl.Add(ts)
 
 	// check new proposal could be submitted
 	if _, err := cl.Participant(0).Set("/foo", false, "bar", store.Permanent); err != nil {
@@ -280,6 +278,7 @@ func TestRestoreSnapshotFromLeader(t *testing.T) {
 	}
 	<-wch.EventChan
 
+	// check node map of two machines are the same
 	g := ts.Participant().node.Nodes()
 	w := cl.Participant(0).node.Nodes()
 	if !reflect.DeepEqual(g, w) {
@@ -352,6 +351,20 @@ func (c *testCluster) wait() {
 	}
 }
 
+func (c *testCluster) Add(s *testServer) {
+	lead, _ := c.Leader()
+	// wait for the node to join the cluster
+	// TODO(yichengq): remove this when we get rid of all timeouts
+	wch, err := c.Participant(int(lead)).Watch(v2machineKVPrefix, true, false, 0)
+	if err != nil {
+		panic(err)
+	}
+	s.Start()
+	<-wch.EventChan
+	c.Size++
+	c.nodes = append(c.nodes, s)
+}
+
 func (c *testCluster) Node(i int) *testServer {
 	return c.nodes[i]
 }