server: add testCluster.Add

and fix possible testing error.
This commit is contained in:
Yicheng Qin 2014-08-19 13:08:49 -07:00
parent f7580cd3b6
commit f7417cf693
2 changed files with 19 additions and 8 deletions

View File

@ -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)

View File

@ -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]
}