Skip to content

Commit

Permalink
Fix Consul readines check
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pschultz committed May 17, 2018
1 parent 4281606 commit ac2a9a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions cert/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"io"
"io/ioutil"
"log"
"math/big"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ac2a9a2

Please sign in to comment.