|
|
@ -2,6 +2,7 @@ package agent
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/testutil"
|
|
|
|
"github.com/hashicorp/consul/consul/structs"
|
|
|
|
"github.com/hashicorp/consul/consul/structs"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"net/http/httptest"
|
|
|
@ -16,18 +17,19 @@ func TestCatalogRegister(t *testing.T) {
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for a leader
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
Datacenter: "dc1",
|
|
|
|
|
|
|
|
Node: "foo",
|
|
|
|
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testutil.WaitForLeader(t, srv.agent.RPC, args)
|
|
|
|
|
|
|
|
|
|
|
|
// Register node
|
|
|
|
// Register node
|
|
|
|
req, err := http.NewRequest("GET", "/v1/catalog/register", nil)
|
|
|
|
req, err := http.NewRequest("GET", "/v1/catalog/register", nil)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
|
|
|
|
Node: "foo",
|
|
|
|
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
req.Body = encodeReq(args)
|
|
|
|
req.Body = encodeReq(args)
|
|
|
|
|
|
|
|
|
|
|
|
obj, err := srv.CatalogRegister(nil, req)
|
|
|
|
obj, err := srv.CatalogRegister(nil, req)
|
|
|
@ -47,17 +49,18 @@ func TestCatalogDeregister(t *testing.T) {
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for a leader
|
|
|
|
args := &structs.DeregisterRequest{
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
Datacenter: "dc1",
|
|
|
|
|
|
|
|
Node: "foo",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testutil.WaitForLeader(t, srv.agent.RPC, args)
|
|
|
|
|
|
|
|
|
|
|
|
// Register node
|
|
|
|
// Register node
|
|
|
|
req, err := http.NewRequest("GET", "/v1/catalog/deregister", nil)
|
|
|
|
req, err := http.NewRequest("GET", "/v1/catalog/deregister", nil)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
args := &structs.DeregisterRequest{
|
|
|
|
|
|
|
|
Node: "foo",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
req.Body = encodeReq(args)
|
|
|
|
req.Body = encodeReq(args)
|
|
|
|
|
|
|
|
|
|
|
|
obj, err := srv.CatalogDeregister(nil, req)
|
|
|
|
obj, err := srv.CatalogDeregister(nil, req)
|
|
|
@ -77,9 +80,6 @@ func TestCatalogDatacenters(t *testing.T) {
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for initialization
|
|
|
|
|
|
|
|
time.Sleep(10 * time.Millisecond)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
obj, err := srv.CatalogDatacenters(nil, nil)
|
|
|
|
obj, err := srv.CatalogDatacenters(nil, nil)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
@ -97,15 +97,15 @@ func TestCatalogNodes(t *testing.T) {
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for a leader
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register node
|
|
|
|
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
Datacenter: "dc1",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
Node: "foo",
|
|
|
|
Node: "foo",
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testutil.WaitForLeader(t, srv.agent.RPC, args)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register node
|
|
|
|
var out struct{}
|
|
|
|
var out struct{}
|
|
|
|
if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil {
|
|
|
|
if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
@ -137,13 +137,13 @@ func TestCatalogNodes_Blocking(t *testing.T) {
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for a leader
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register node
|
|
|
|
|
|
|
|
args := &structs.DCSpecificRequest{
|
|
|
|
args := &structs.DCSpecificRequest{
|
|
|
|
Datacenter: "dc1",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testutil.WaitForLeader(t, srv.agent.RPC, args)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register node
|
|
|
|
var out structs.IndexedNodes
|
|
|
|
var out structs.IndexedNodes
|
|
|
|
if err := srv.agent.RPC("Catalog.ListNodes", *args, &out); err != nil {
|
|
|
|
if err := srv.agent.RPC("Catalog.ListNodes", *args, &out); err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
@ -152,7 +152,7 @@ func TestCatalogNodes_Blocking(t *testing.T) {
|
|
|
|
// Do an update in a little while
|
|
|
|
// Do an update in a little while
|
|
|
|
start := time.Now()
|
|
|
|
start := time.Now()
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
time.Sleep(50 * time.Millisecond)
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
Datacenter: "dc1",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
Node: "foo",
|
|
|
|
Node: "foo",
|
|
|
@ -178,7 +178,7 @@ func TestCatalogNodes_Blocking(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Should block for a while
|
|
|
|
// Should block for a while
|
|
|
|
if time.Now().Sub(start) < 100*time.Millisecond {
|
|
|
|
if time.Now().Sub(start) < 50 * time.Millisecond {
|
|
|
|
t.Fatalf("too fast")
|
|
|
|
t.Fatalf("too fast")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -198,10 +198,6 @@ func TestCatalogServices(t *testing.T) {
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for a leader
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register node
|
|
|
|
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
Datacenter: "dc1",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
Node: "foo",
|
|
|
|
Node: "foo",
|
|
|
@ -210,6 +206,10 @@ func TestCatalogServices(t *testing.T) {
|
|
|
|
Service: "api",
|
|
|
|
Service: "api",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testutil.WaitForLeader(t, srv.agent.RPC, args)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register node
|
|
|
|
var out struct{}
|
|
|
|
var out struct{}
|
|
|
|
if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil {
|
|
|
|
if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
@ -240,10 +240,6 @@ func TestCatalogServiceNodes(t *testing.T) {
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for a leader
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register node
|
|
|
|
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
Datacenter: "dc1",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
Node: "foo",
|
|
|
|
Node: "foo",
|
|
|
@ -253,6 +249,10 @@ func TestCatalogServiceNodes(t *testing.T) {
|
|
|
|
Tags: []string{"a"},
|
|
|
|
Tags: []string{"a"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testutil.WaitForLeader(t, srv.agent.RPC, args)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register node
|
|
|
|
var out struct{}
|
|
|
|
var out struct{}
|
|
|
|
if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil {
|
|
|
|
if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
@ -283,10 +283,6 @@ func TestCatalogNodeServices(t *testing.T) {
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
defer srv.agent.Shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for a leader
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register node
|
|
|
|
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
args := &structs.RegisterRequest{
|
|
|
|
Datacenter: "dc1",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
Node: "foo",
|
|
|
|
Node: "foo",
|
|
|
@ -296,6 +292,10 @@ func TestCatalogNodeServices(t *testing.T) {
|
|
|
|
Tags: []string{"a"},
|
|
|
|
Tags: []string{"a"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testutil.WaitForLeader(t, srv.agent.RPC, args)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register node
|
|
|
|
var out struct{}
|
|
|
|
var out struct{}
|
|
|
|
if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil {
|
|
|
|
if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|