From dde3b90632f83ed843281cbe9acd406f33a5b923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Tis=C3=A4ter?= Date: Wed, 7 May 2014 22:45:16 +0200 Subject: [PATCH] Remove all sleeps from `force_leave_test.go` --- command/force_leave_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/command/force_leave_test.go b/command/force_leave_test.go index 6b66b4fb1c..40a2224f7b 100644 --- a/command/force_leave_test.go +++ b/command/force_leave_test.go @@ -2,12 +2,12 @@ package command import ( "fmt" + "github.com/hashicorp/consul/testutil" "github.com/hashicorp/serf/serf" - "github.com/hashicorp/serf/testutil" "github.com/mitchellh/cli" "strings" "testing" - "time" + "errors" ) func TestForceLeaveCommand_implements(t *testing.T) { @@ -26,13 +26,9 @@ func TestForceLeaveCommandRun(t *testing.T) { t.Fatalf("err: %s", err) } - testutil.Yield() - // Forcibly shutdown a2 so that it appears "failed" in a1 a2.Shutdown() - time.Sleep(time.Second) - ui := new(cli.MockUi) c := &ForceLeaveCommand{Ui: ui} args := []string{ @@ -50,9 +46,14 @@ func TestForceLeaveCommandRun(t *testing.T) { t.Fatalf("should have 2 members: %#v", m) } - if m[1].Status != serf.StatusLeft { - t.Fatalf("should be left: %#v", m[1]) - } + testutil.WaitForResult(func() (bool, error) { + m = a1.agent.LANMembers() + success := m[1].Status == serf.StatusLeft + err := errors.New(m[1].Status.String()) + return success, err + }, func(err error) { + t.Fatalf("member status is %v, not left", err) + }) } func TestForceLeaveCommandRun_noAddrs(t *testing.T) {