|
|
|
@ -2,12 +2,12 @@ package agent
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/hashicorp/consul/testutil"
|
|
|
|
|
"github.com/hashicorp/consul/consul/structs"
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/http/httptest"
|
|
|
|
|
"os"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestHealthChecksInState(t *testing.T) {
|
|
|
|
@ -16,8 +16,11 @@ func TestHealthChecksInState(t *testing.T) {
|
|
|
|
|
defer srv.Shutdown()
|
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
|
|
|
|
|
|
// Wait for a leader
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
|
Datacenter: "dc1",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
testutil.WaitForLeader(t, srv.agent.RPC, args)
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequest("GET", "/v1/health/state/passing?dc=dc1", nil)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -44,8 +47,11 @@ func TestHealthNodeChecks(t *testing.T) {
|
|
|
|
|
defer srv.Shutdown()
|
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
|
|
|
|
|
|
// Wait for a leader
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
|
Datacenter: "dc1",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
testutil.WaitForLeader(t, srv.agent.RPC, args)
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequest("GET",
|
|
|
|
|
fmt.Sprintf("/v1/health/node/%s?dc=dc1", srv.agent.config.NodeName), nil)
|
|
|
|
@ -73,10 +79,6 @@ func TestHealthServiceChecks(t *testing.T) {
|
|
|
|
|
defer srv.Shutdown()
|
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
|
|
|
|
|
|
// Wait for a leader
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
|
|
// Create a service check
|
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
|
Datacenter: "dc1",
|
|
|
|
|
Node: srv.agent.config.NodeName,
|
|
|
|
@ -87,6 +89,10 @@ func TestHealthServiceChecks(t *testing.T) {
|
|
|
|
|
ServiceID: "consul",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
testutil.WaitForLeader(t, srv.agent.RPC, args)
|
|
|
|
|
|
|
|
|
|
// Create a service check
|
|
|
|
|
var out struct{}
|
|
|
|
|
if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil {
|
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
@ -117,8 +123,11 @@ func TestHealthServiceNodes(t *testing.T) {
|
|
|
|
|
defer srv.Shutdown()
|
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
|
|
|
|
|
|
// Wait for a leader
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
|
Datacenter: "dc1",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
testutil.WaitForLeader(t, srv.agent.RPC, args)
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequest("GET", "/v1/health/service/consul?dc=dc1", nil)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -145,10 +154,6 @@ func TestHealthServiceNodes_PassingFilter(t *testing.T) {
|
|
|
|
|
defer srv.Shutdown()
|
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
|
|
|
|
|
|
// Wait for a leader
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
|
|
// Create a failing service check
|
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
|
Datacenter: "dc1",
|
|
|
|
|
Node: srv.agent.config.NodeName,
|
|
|
|
@ -160,6 +165,10 @@ func TestHealthServiceNodes_PassingFilter(t *testing.T) {
|
|
|
|
|
Status: structs.HealthCritical,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
testutil.WaitForLeader(t, srv.agent.RPC, args)
|
|
|
|
|
|
|
|
|
|
// Create a failing service check
|
|
|
|
|
var out struct{}
|
|
|
|
|
if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil {
|
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
|