From ac2a9a2cb267c340e72826b6fb5f762e681052c9 Mon Sep 17 00:00:00 2001 From: Peter Schultz Date: Thu, 17 May 2018 17:30:44 +0200 Subject: [PATCH] Fix Consul readines check Consul added suppported for compressed HTTP responses in 1.0.7, which means we can no longer rely on the Content-Length response header when checking if the server is ready yet. --- Makefile | 4 ++-- cert/source_test.go | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 6d2ff11ba..3a9ca9421 100644 --- a/Makefile +++ b/Makefile @@ -27,8 +27,8 @@ GOVENDOR = $(shell which govendor) VENDORFMT = $(shell which vendorfmt) # pin versions for CI builds -CI_CONSUL_VERSION=1.0.6 -CI_VAULT_VERSION=0.9.6 +CI_CONSUL_VERSION=1.1.0 +CI_VAULT_VERSION=0.10.1 CI_GO_VERSION=1.10.2 # all is the default target diff --git a/cert/source_test.go b/cert/source_test.go index 30c407f66..32c27442d 100644 --- a/cert/source_test.go +++ b/cert/source_test.go @@ -9,6 +9,7 @@ import ( "crypto/x509/pkix" "encoding/pem" "fmt" + "io" "io/ioutil" "log" "math/big" @@ -250,8 +251,18 @@ func TestConsulSource(t *testing.T) { resp, err := http.Get("http://127.0.0.1:8500/v1/status/leader") // /v1/status/leader returns '\n""' while consul is in leader election mode // and '"127.0.0.1:8300"' when not. So we punt by checking the - // Content-Length header instead of the actual body content :) - return err == nil && resp.StatusCode == 200 && resp.ContentLength > 10 + // body length instead of the actual body content :) + if err != nil { + return false + } + defer resp.Body.Close() + + if resp.StatusCode != 200 { + return false + } + + n, err := io.Copy(ioutil.Discard, resp.Body) + return err == nil && n > 10 } // We need give consul ~8-10 seconds to become ready until I've