Browse Source

server: fix testings

Make WaitMode panic to alert.
Yicheng Qin 11 years ago
parent
commit
33465a7e42
3 changed files with 17 additions and 21 deletions
  1. 4 4
      etcd/etcd_functional_test.go
  2. 3 3
      etcd/etcd_start_test.go
  3. 10 14
      etcd/etcd_test.go

+ 4 - 4
etcd/etcd_functional_test.go

@@ -42,7 +42,7 @@ func TestKillLeader(t *testing.T) {
 				t.Errorf("#%d.%d: lead = %d, want not %d", i, j, g, lead)
 			}
 			cl.Node(int(lead)).Start()
-			cl.Node(int(lead)).WaitMode(participantMode, 3)
+			cl.Node(int(lead)).WaitMode(participantMode)
 		}
 		cl.Destroy()
 	}
@@ -72,7 +72,7 @@ func TestKillRandom(t *testing.T) {
 			cl.Leader()
 			for k := range toKill {
 				cl.Node(int(k)).Start()
-				cl.Node(int(k)).WaitMode(participantMode, 3)
+				cl.Node(int(k)).WaitMode(participantMode)
 			}
 		}
 		cl.Destroy()
@@ -94,7 +94,7 @@ func TestJoinThroughFollower(t *testing.T) {
 			c.Peers = []string{seed}
 			ts := &testServer{Config: c, Id: int64(i)}
 			ts.Start()
-			ts.WaitMode(participantMode, 3)
+			ts.WaitMode(participantMode)
 			cl.nodes = append(cl.nodes, ts)
 			cl.Leader()
 			seed = ts.URL
@@ -138,7 +138,7 @@ func TestFiveNodeKillOneAndRecover(t *testing.T) {
 		cl.Node(i).Stop()
 		cl.Leader()
 		cl.Node(i).Start()
-		cl.Node(i).WaitMode(participantMode, 3)
+		cl.Node(i).WaitMode(participantMode)
 		cl.Leader()
 	}
 	cl.Destroy()

+ 3 - 3
etcd/etcd_start_test.go

@@ -98,7 +98,7 @@ func TestBootstrapByEmptyPeers(t *testing.T) {
 	ts := testServer{Id: id}
 	ts.Start()
 	defer ts.Destroy()
-	ts.WaitMode(participantMode, 3)
+	ts.WaitMode(participantMode)
 	if ts.Participant().node.Leader() != id {
 		t.Errorf("leader = %x, want %x", ts.Participant().node.Leader(), id)
 	}
@@ -114,7 +114,7 @@ func TestBootstrapByDiscoveryService(t *testing.T) {
 	c.Discovery = discoverService.URL(0) + "/v2/keys/_etcd/registry/1"
 	ts := testServer{Id: bootstrapId, Config: c}
 	ts.Start()
-	ts.WaitMode(participantMode, 3)
+	ts.WaitMode(participantMode)
 	err := ts.Destroy()
 	if err != nil {
 		t.Fatalf("server stop err = %v, want nil", err)
@@ -152,7 +152,7 @@ func TestRunByDiscoveryService(t *testing.T) {
 	ts.Start()
 	defer ts.Destroy()
 
-	ts.WaitMode(participantMode, 3)
+	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)

+ 10 - 14
etcd/etcd_test.go

@@ -120,7 +120,7 @@ func TestRemove(t *testing.T) {
 						t.Fatal(err)
 					}
 				}
-				cl.Node(i).WaitMode(standbyMode, 10)
+				cl.Node(i).WaitMode(standbyMode)
 			}
 			cl.Destroy()
 		}
@@ -193,7 +193,7 @@ func TestSingleNodeRecovery(t *testing.T) {
 	ts.Start()
 	defer ts.Destroy()
 
-	ts.WaitMode(participantMode, 1)
+	ts.WaitMode(participantMode)
 
 	key := "/foo"
 	ev, err := ts.Participant().Set(key, false, "bar", time.Now().Add(time.Second*100))
@@ -204,7 +204,7 @@ func TestSingleNodeRecovery(t *testing.T) {
 
 	ts = testServer{Id: ts.Id, Config: c}
 	ts.Start()
-	ts.WaitMode(participantMode, 1)
+	ts.WaitMode(participantMode)
 	w, err := ts.Participant().Store.Watch(key, false, false, ev.Index())
 	if err != nil {
 		t.Fatal(err)
@@ -252,7 +252,7 @@ func TestRestoreSnapshotFromLeader(t *testing.T) {
 	ts := testServer{Config: c, Id: 1}
 	ts.Start()
 	defer ts.Destroy()
-	ts.WaitMode(participantMode, 1)
+	ts.WaitMode(participantMode)
 
 	// check new proposal could be submitted
 	if _, err := cl.Participant(0).Set("/foo", false, "bar", store.Permanent); err != nil {
@@ -302,9 +302,7 @@ func (c *testCluster) Start() {
 	c.nodes = nodes
 	nodes[0] = &testServer{Id: 0, TLS: c.TLS}
 	nodes[0].Start()
-	if !nodes[0].WaitMode(participantMode, 10) {
-		panic("cannot wait until participantMode")
-	}
+	nodes[0].WaitMode(participantMode)
 
 	seed := nodes[0].URL
 	for i := 1; i < c.Size; i++ {
@@ -319,9 +317,7 @@ func (c *testCluster) Start() {
 		// or this configuration request might be dropped.
 		// Or it could be a slow join because it needs to retry.
 		// TODO: this might not be true if we add param for retry interval.
-		if !s.WaitMode(participantMode, 20) {
-			panic("cannot wait until participantMode")
-		}
+		s.WaitMode(participantMode)
 		w, err := s.Participant().Watch(v2machineKVPrefix, true, false, uint64(i))
 		if err != nil {
 			panic(err)
@@ -478,14 +474,14 @@ func (s *testServer) Start() {
 	go e.Run()
 }
 
-func (s *testServer) WaitMode(mode int64, timeout int) bool {
-	for i := 0; i < timeout+1; i++ {
+func (s *testServer) WaitMode(mode int64) {
+	for i := 0; i < 30; i++ {
 		if s.e.mode.Get() == mode {
-			return true
+			return
 		}
 		time.Sleep(time.Millisecond)
 	}
-	return false
+	panic("waitMode should never take more than 30ms.")
 }
 
 func (s *testServer) Participant() *participant {