From 091e628b389bbe3e620c25f1dcfb493d7f0deed7 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 22 May 2018 14:39:51 -0700 Subject: [PATCH] Unit test for dev agent --- command/agent/agent.go | 2 +- command/agent/agent_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index d6eaf20abd9..a75dd1fe77f 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -322,7 +322,7 @@ func (a *Agent) clientConfig() (*clientconfig.Config, error) { conf.Servers = a.config.Client.Servers if a.server != nil { conf.Servers = append(conf.Servers, - a.config.Addresses.RPC, + a.config.normalizedAddrs.RPC, a.config.AdvertiseAddrs.RPC) } diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index 2926231239c..89c556808e6 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -9,7 +9,9 @@ import ( "testing" "time" + cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/helper" + "github.com/hashicorp/nomad/nomad/structs" sconfig "github.com/hashicorp/nomad/nomad/structs/config" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -1057,3 +1059,24 @@ func TestServer_ShouldReload_ShouldHandleMultipleChanges(t *testing.T) { require.False(shouldReloadRPC) } } + +func TestAgent_ProxyRPC_Dev(t *testing.T) { + t.Parallel() + agent := NewTestAgent(t, t.Name(), nil) + defer agent.Shutdown() + + id := agent.client.NodeID() + req := &structs.NodeSpecificRequest{ + NodeID: id, + QueryOptions: structs.QueryOptions{ + Region: agent.server.Region(), + }, + } + + time.Sleep(100 * time.Millisecond) + + var resp cstructs.ClientStatsResponse + if err := agent.RPC("ClientStats.Stats", req, &resp); err != nil { + t.Fatalf("err: %v", err) + } +}