From 4742adb36c6ecffc1de84c7b4402e25739c9f833 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 26 Jan 2017 00:13:03 -0500 Subject: [PATCH 1/2] Check to see if TaggedAddresses have been populated This ensures the node's anti-entropy checks have finished before telling the client Consul is ready. --- testutil/server.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/testutil/server.go b/testutil/server.go index cd5fa128e..eaa0a53d7 100644 --- a/testutil/server.go +++ b/testutil/server.go @@ -292,6 +292,7 @@ func (s *TestServer) waitForAPI() { // waitForLeader waits for the Consul server's HTTP API to become // available, and then waits for a known leader and an index of // 1 or more to be observed to confirm leader election is done. +// It then waits to ensure the anti-entropy checks have completed. func (s *TestServer) waitForLeader() { WaitForResult(func() (bool, error) { // Query the API and check the status code @@ -312,6 +313,25 @@ func (s *TestServer) waitForLeader() { if resp.Header.Get("X-Consul-Index") == "0" { return false, fmt.Errorf("Consul index is 0") } + + var parsed []map[string]interface{} + dec := json.NewDecoder(resp.Body) + if err := dec.Decode(&parsed); err != nil { + return false, err + } + + if len(parsed) < 1 { + return false, fmt.Errorf("No nodes") + } + + taggedAddresses, ok := parsed[0]["TaggedAddresses"].(map[string]interface{}) + if !ok { + return false, fmt.Errorf("Missing tagged addresses") + } + if _, ok := taggedAddresses["lan"]; !ok { + return false, fmt.Errorf("No lan tagged addresses") + } + return true, nil }, func(err error) { defer s.Stop() From efc1c8614b1de5c863da52b62eb503a6d3864c59 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 26 Jan 2017 00:13:34 -0500 Subject: [PATCH 2/2] Sleep for longer, but try less often This fixes an issue where the system can quickly run out of file descriptors because they are accumulating faster than the kernel can release them. --- testutil/wait.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/testutil/wait.go b/testutil/wait.go index ae2439437..40ae384ae 100644 --- a/testutil/wait.go +++ b/testutil/wait.go @@ -1,19 +1,20 @@ package testutil import ( - "github.com/hashicorp/consul/consul/structs" "testing" "time" + + "github.com/hashicorp/consul/consul/structs" ) type testFn func() (bool, error) type errorFn func(error) func WaitForResult(test testFn, error errorFn) { - retries := 1000 + retries := 100 for retries > 0 { - time.Sleep(10 * time.Millisecond) + time.Sleep(100 * time.Millisecond) retries-- success, err := test()