From 2c9bb57c0f4fd34def261b9ab0d59e17f498afd1 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Fri, 9 Jan 2015 19:10:17 -0800 Subject: [PATCH] consul: fix server left test --- consul/leader_test.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/consul/leader_test.go b/consul/leader_test.go index 7c51dc32a637..20015cb139fe 100644 --- a/consul/leader_test.go +++ b/consul/leader_test.go @@ -310,23 +310,24 @@ func TestLeader_LeftServer(t *testing.T) { }) } - // Kill any server - servers[0].Shutdown() - time.Sleep(100 * time.Millisecond) + testutil.WaitForResult(func() (bool, error) { + // Kill any server + servers[0].Shutdown() - // Force remove the non-leader (transition to left state) - if err := servers[1].RemoveFailedNode(servers[0].config.NodeName); err != nil { - t.Fatalf("err: %v", err) - } + // Force remove the non-leader (transition to left state) + if err := servers[1].RemoveFailedNode(servers[0].config.NodeName); err != nil { + t.Fatalf("err: %v", err) + } - for _, s := range servers[1:] { - testutil.WaitForResult(func() (bool, error) { + for _, s := range servers[1:] { peers, _ := s.raftPeers.Peers() return len(peers) == 2, errors.New(fmt.Sprintf("%v", peers)) - }, func(err error) { - t.Fatalf("should have 2 peers: %v", err) - }) - } + } + + return true, nil + }, func(err error) { + t.Fatalf("err: %s", err) + }) } func TestLeader_LeftLeader(t *testing.T) {