rpc: fix TestServer_Leave

wait for the leader election.
This commit is contained in:
Frank Schroeder 2017-06-26 14:35:34 +02:00 committed by Frank Schröder
parent 4a073aec1c
commit 06ad8e96be
1 changed files with 26 additions and 22 deletions

View File

@ -361,19 +361,21 @@ func TestServer_LeaveLeader(t *testing.T) {
// Try to join // Try to join
joinLAN(t, s2, s1) joinLAN(t, s2, s1)
retry.Run(t, func(r *retry.R) { testrpc.WaitForLeader(t, s1.RPC, "dc1")
r.Check(wantPeers(s1, 2)) testrpc.WaitForLeader(t, s2.RPC, "dc1")
r.Check(wantPeers(s2, 2))
})
// Issue a leave to the leader // Issue a leave to the leader
for _, s := range []*Server{s1, s2} { var err error
if !s.IsLeader() { switch {
continue case s1.IsLeader():
} err = s1.Leave()
if err := s.Leave(); err != nil { case s2.IsLeader():
t.Fatalf("err: %v", err) err = s2.Leave()
} default:
t.Fatal("no leader")
}
if err != nil {
t.Fatal("leave failed: ", err)
} }
// Should lose a peer // Should lose a peer
@ -396,19 +398,21 @@ func TestServer_Leave(t *testing.T) {
// Try to join // Try to join
joinLAN(t, s2, s1) joinLAN(t, s2, s1)
retry.Run(t, func(r *retry.R) { testrpc.WaitForLeader(t, s1.RPC, "dc1")
r.Check(wantPeers(s1, 2)) testrpc.WaitForLeader(t, s2.RPC, "dc1")
r.Check(wantPeers(s2, 2))
})
// Issue a leave to the non-leader // Issue a leave to the non-leader
for _, s := range []*Server{s1, s2} { var err error
if s.IsLeader() { switch {
continue case s1.IsLeader():
} err = s2.Leave()
if err := s.Leave(); err != nil { case s2.IsLeader():
t.Fatalf("err: %v", err) err = s1.Leave()
} default:
t.Fatal("no leader")
}
if err != nil {
t.Fatal("leave failed: ", err)
} }
// Should lose a peer // Should lose a peer