|
|
@ -1737,11 +1737,7 @@ func TestAgent_RestoreServiceWithAliasCheck(t *testing.T) {
|
|
|
|
testCtx, testCancel := context.WithCancel(context.Background())
|
|
|
|
testCtx, testCancel := context.WithCancel(context.Background())
|
|
|
|
defer testCancel()
|
|
|
|
defer testCancel()
|
|
|
|
|
|
|
|
|
|
|
|
testHTTPServer, returnPort := launchHTTPCheckServer(t, testCtx)
|
|
|
|
testHTTPServer := launchHTTPCheckServer(t, testCtx)
|
|
|
|
defer func() {
|
|
|
|
|
|
|
|
testHTTPServer.Close()
|
|
|
|
|
|
|
|
returnPort()
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
registerServicesAndChecks := func(t *testing.T, a *TestAgent) {
|
|
|
|
registerServicesAndChecks := func(t *testing.T, a *TestAgent) {
|
|
|
|
// add one persistent service with a simple check
|
|
|
|
// add one persistent service with a simple check
|
|
|
@ -1846,11 +1842,8 @@ node_name = "` + a.Config.NodeName + `"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func launchHTTPCheckServer(t *testing.T, ctx context.Context) (srv *httptest.Server, returnPortsFn func()) {
|
|
|
|
func launchHTTPCheckServer(t *testing.T, ctx context.Context) *httptest.Server {
|
|
|
|
ports := freeport.MustTake(1)
|
|
|
|
addr := net.JoinHostPort("127.0.0.1", strconv.Itoa(freeport.Port(t)))
|
|
|
|
port := ports[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addr := net.JoinHostPort("127.0.0.1", strconv.Itoa(port))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var lc net.ListenConfig
|
|
|
|
var lc net.ListenConfig
|
|
|
|
listener, err := lc.Listen(ctx, "tcp", addr)
|
|
|
|
listener, err := lc.Listen(ctx, "tcp", addr)
|
|
|
@ -1861,12 +1854,13 @@ func launchHTTPCheckServer(t *testing.T, ctx context.Context) (srv *httptest.Ser
|
|
|
|
_, _ = w.Write([]byte("OK\n"))
|
|
|
|
_, _ = w.Write([]byte("OK\n"))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
srv = &httptest.Server{
|
|
|
|
srv := &httptest.Server{
|
|
|
|
Listener: listener,
|
|
|
|
Listener: listener,
|
|
|
|
Config: &http.Server{Handler: handler},
|
|
|
|
Config: &http.Server{Handler: handler},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
srv.Start()
|
|
|
|
srv.Start()
|
|
|
|
return srv, func() { freeport.Return(ports) }
|
|
|
|
t.Cleanup(srv.Close)
|
|
|
|
|
|
|
|
return srv
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestAgent_AddCheck_Alias(t *testing.T) {
|
|
|
|
func TestAgent_AddCheck_Alias(t *testing.T) {
|
|
|
@ -4704,14 +4698,12 @@ func TestAgent_JoinWAN_viaMeshGateway(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
t.Parallel()
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
|
|
gwPort := freeport.MustTake(1)
|
|
|
|
port := freeport.Port(t)
|
|
|
|
defer freeport.Return(gwPort)
|
|
|
|
gwAddr := ipaddr.FormatAddressPort("127.0.0.1", port)
|
|
|
|
gwAddr := ipaddr.FormatAddressPort("127.0.0.1", gwPort[0])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Due to some ordering, we'll have to manually configure these ports in
|
|
|
|
// Due to some ordering, we'll have to manually configure these ports in
|
|
|
|
// advance.
|
|
|
|
// advance.
|
|
|
|
secondaryRPCPorts := freeport.MustTake(2)
|
|
|
|
secondaryRPCPorts := freeport.GetN(t, 2)
|
|
|
|
defer freeport.Return(secondaryRPCPorts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
a1 := StartTestAgent(t, TestAgent{Name: "bob", HCL: `
|
|
|
|
a1 := StartTestAgent(t, TestAgent{Name: "bob", HCL: `
|
|
|
|
domain = "consul"
|
|
|
|
domain = "consul"
|
|
|
@ -4765,7 +4757,7 @@ func TestAgent_JoinWAN_viaMeshGateway(t *testing.T) {
|
|
|
|
ID: "mesh-gateway",
|
|
|
|
ID: "mesh-gateway",
|
|
|
|
Name: "mesh-gateway",
|
|
|
|
Name: "mesh-gateway",
|
|
|
|
Meta: map[string]string{structs.MetaWANFederationKey: "1"},
|
|
|
|
Meta: map[string]string{structs.MetaWANFederationKey: "1"},
|
|
|
|
Port: gwPort[0],
|
|
|
|
Port: port,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err := http.NewRequest("PUT", "/v1/agent/service/register", jsonReader(args))
|
|
|
|
req, err := http.NewRequest("PUT", "/v1/agent/service/register", jsonReader(args))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
@ -4879,7 +4871,7 @@ func TestAgent_JoinWAN_viaMeshGateway(t *testing.T) {
|
|
|
|
ID: "mesh-gateway",
|
|
|
|
ID: "mesh-gateway",
|
|
|
|
Name: "mesh-gateway",
|
|
|
|
Name: "mesh-gateway",
|
|
|
|
Meta: map[string]string{structs.MetaWANFederationKey: "1"},
|
|
|
|
Meta: map[string]string{structs.MetaWANFederationKey: "1"},
|
|
|
|
Port: gwPort[0],
|
|
|
|
Port: port,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err := http.NewRequest("PUT", "/v1/agent/service/register", jsonReader(args))
|
|
|
|
req, err := http.NewRequest("PUT", "/v1/agent/service/register", jsonReader(args))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
@ -4894,7 +4886,7 @@ func TestAgent_JoinWAN_viaMeshGateway(t *testing.T) {
|
|
|
|
ID: "mesh-gateway",
|
|
|
|
ID: "mesh-gateway",
|
|
|
|
Name: "mesh-gateway",
|
|
|
|
Name: "mesh-gateway",
|
|
|
|
Meta: map[string]string{structs.MetaWANFederationKey: "1"},
|
|
|
|
Meta: map[string]string{structs.MetaWANFederationKey: "1"},
|
|
|
|
Port: gwPort[0],
|
|
|
|
Port: port,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req, err := http.NewRequest("PUT", "/v1/agent/service/register", jsonReader(args))
|
|
|
|
req, err := http.NewRequest("PUT", "/v1/agent/service/register", jsonReader(args))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|