Remove all sleeps from `agent_endpoint_test.go`

This commit is contained in:
William Tisäter 2014-05-07 22:50:18 +02:00
parent dde3b90632
commit ab209c0176
1 changed files with 9 additions and 7 deletions

View File

@ -2,12 +2,14 @@ package agent
import ( import (
"fmt" "fmt"
"github.com/hashicorp/consul/testutil"
"github.com/hashicorp/consul/consul/structs" "github.com/hashicorp/consul/consul/structs"
"github.com/hashicorp/serf/serf" "github.com/hashicorp/serf/serf"
"net/http" "net/http"
"os" "os"
"testing" "testing"
"time" "time"
"errors"
) )
func TestHTTPAgentServices(t *testing.T) { func TestHTTPAgentServices(t *testing.T) {
@ -189,9 +191,7 @@ func TestHTTPAgentForceLeave(t *testing.T) {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
// Shutdown, wait for detection
a2.Shutdown() a2.Shutdown()
time.Sleep(500 * time.Millisecond)
// Force leave now // Force leave now
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/force-leave/%s", a2.config.NodeName), nil) req, err := http.NewRequest("GET", fmt.Sprintf("/v1/agent/force-leave/%s", a2.config.NodeName), nil)
@ -207,11 +207,13 @@ func TestHTTPAgentForceLeave(t *testing.T) {
t.Fatalf("Err: %v", obj) t.Fatalf("Err: %v", obj)
} }
// SHould be left testutil.WaitForResult(func() (bool, error) {
mem := srv.agent.LANMembers() m := srv.agent.LANMembers()
if mem[1].Status != serf.StatusLeft { success := m[1].Status == serf.StatusLeft
t.Fatalf("should have left: %v", mem) return success, errors.New(m[1].Status.String())
} }, func(err error) {
t.Fatalf("member status is %v, should be left", err)
})
} }
func TestHTTPAgentRegisterCheck(t *testing.T) { func TestHTTPAgentRegisterCheck(t *testing.T) {