mirror of https://github.com/status-im/consul.git
api: test for a known leader as well as index > 0
This commit is contained in:
parent
1a3a54d3e6
commit
fab30406be
|
@ -7,7 +7,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -81,15 +80,18 @@ func newTestServer(t *testing.T) *testServer {
|
||||||
// Allow the server some time to start, and verify we have a leader.
|
// Allow the server some time to start, and verify we have a leader.
|
||||||
client := new(http.Client)
|
client := new(http.Client)
|
||||||
testutil.WaitForResult(func() (bool, error) {
|
testutil.WaitForResult(func() (bool, error) {
|
||||||
resp, err := client.Get("http://127.0.0.1:18800/v1/status/leader")
|
resp, err := client.Get("http://127.0.0.1:18800/v1/catalog/nodes")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
// Ensure we have a leader and a node registeration
|
||||||
if err != nil || !strings.Contains(string(body), "18000") {
|
if leader := resp.Header.Get("X-Consul-KnownLeader"); leader != "true" {
|
||||||
return false, fmt.Errorf("No leader")
|
return false, fmt.Errorf("Consul leader status: %#v", leader)
|
||||||
|
}
|
||||||
|
if resp.Header.Get("X-Consul-Index") == "0" {
|
||||||
|
return false, fmt.Errorf("Consul index is 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
|
|
Loading…
Reference in New Issue