diff --git a/consul/client.go b/consul/client.go index 78643a34e..4f2de2a19 100644 --- a/consul/client.go +++ b/consul/client.go @@ -340,7 +340,7 @@ func (c *Client) RPC(method string, args interface{}, reply interface{}) error { // Stats is used to return statistics for debugging and insight // for various sub-systems func (c *Client) Stats() map[string]map[string]string { - numServers := c.serverMgr.GetNumServers() + numServers := c.serverMgr.NumServers() toString := func(v uint64) string { return strconv.FormatUint(v, 10) diff --git a/consul/client_test.go b/consul/client_test.go index 124980094..8caf76524 100644 --- a/consul/client_test.go +++ b/consul/client_test.go @@ -84,7 +84,7 @@ func TestClient_JoinLAN(t *testing.T) { t.Fatalf("err: %v", err) } testutil.WaitForResult(func() (bool, error) { - return c1.serverMgr.GetNumServers() == 1, nil + return c1.serverMgr.NumServers() == 1, nil }, func(err error) { t.Fatalf("expected consul server") }) @@ -100,7 +100,7 @@ func TestClient_JoinLAN(t *testing.T) { // Check we have a new consul testutil.WaitForResult(func() (bool, error) { - return c1.serverMgr.GetNumServers() == 1, nil + return c1.serverMgr.NumServers() == 1, nil }, func(err error) { t.Fatalf("expected consul server") }) diff --git a/consul/server_manager/server_manager.go b/consul/server_manager/server_manager.go index e3342a923..b327b20f2 100644 --- a/consul/server_manager/server_manager.go +++ b/consul/server_manager/server_manager.go @@ -162,14 +162,6 @@ func (sm *ServerManager) FindServer() *server_details.ServerDetails { } } -// GetNumServers takes out an internal "read lock" and returns the number of -// servers. numServers includes both healthy and unhealthy servers. -func (sm *ServerManager) GetNumServers() (numServers int) { - serverCfg := sm.getServerConfig() - numServers = len(serverCfg.servers) - return numServers -} - // getServerConfig is a convenience method which hides the locking semantics // of atomic.Value from the caller. func (sm *ServerManager) getServerConfig() serverConfig { @@ -218,6 +210,14 @@ func (sm *ServerManager) NotifyFailedServer(server *server_details.ServerDetails } } +// NumServers takes out an internal "read lock" and returns the number of +// servers. numServers includes both healthy and unhealthy servers. +func (sm *ServerManager) NumServers() (numServers int) { + serverCfg := sm.getServerConfig() + numServers = len(serverCfg.servers) + return numServers +} + // RebalanceServers takes out an internal write lock and shuffles the list of // servers on this agent. This allows for a redistribution of work across // consul servers and provides a guarantee that the order of the server list diff --git a/consul/server_manager/server_manager_test.go b/consul/server_manager/server_manager_test.go index b5285d505..2fa61a3dc 100644 --- a/consul/server_manager/server_manager_test.go +++ b/consul/server_manager/server_manager_test.go @@ -84,14 +84,14 @@ func TestServerManager_FindServer(t *testing.T) { func TestServerManager_GetNumServers(t *testing.T) { sm := makeMockServerManager() var num int - num = sm.GetNumServers() + num = sm.NumServers() if num != 0 { t.Fatalf("Expected zero servers to start") } s := &server_details.ServerDetails{} sm.AddServer(s) - num = sm.GetNumServers() + num = sm.NumServers() if num != 1 { t.Fatalf("Expected one server after AddServer") }