diff options
| -rw-r--r-- | src/rabbit_peer_discovery_dns.erl | 8 | ||||
| -rw-r--r-- | test/peer_discovery_dns_SUITE.erl | 85 |
2 files changed, 90 insertions, 3 deletions
diff --git a/src/rabbit_peer_discovery_dns.erl b/src/rabbit_peer_discovery_dns.erl index 3e9e2d988a..e2b1f57312 100644 --- a/src/rabbit_peer_discovery_dns.erl +++ b/src/rabbit_peer_discovery_dns.erl @@ -21,7 +21,7 @@ -export([list_nodes/0, register/0, unregister/0]). %% for tests --export([discover_nodes/2]). +-export([discover_nodes/2, discover_hostnames/2]). %% %% API @@ -59,10 +59,12 @@ unregister() -> %% discover_nodes(SeedHostname, LongNamesUsed) -> - [rabbit_peer_discovery:append_node_prefix(H) || H <- discover_hostnames(SeedHostname, LongNamesUsed)]. + [rabbit_peer_discovery:append_node_prefix(H) || + H <- discover_hostnames(SeedHostname, LongNamesUsed)]. discover_hostnames(SeedHostname, LongNamesUsed) -> - Hosts = [extract_host(inet_res:gethostbyaddr(A), LongNamesUsed) || A <- inet_res:lookup(SeedHostname, in, a)], + Hosts = [extract_host(inet_res:gethostbyaddr(A), LongNamesUsed) || + A <- inet_res:lookup(SeedHostname, in, a)], lists:filter(fun(E) -> E =/= error end, Hosts). %% long node names are used diff --git a/test/peer_discovery_dns_SUITE.erl b/test/peer_discovery_dns_SUITE.erl new file mode 100644 index 0000000000..13bf93ca86 --- /dev/null +++ b/test/peer_discovery_dns_SUITE.erl @@ -0,0 +1,85 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is GoPivotal, Inc. +%% Copyright (c) 2011-2016 Pivotal Software, Inc. All rights reserved. +%% + +-module(peer_discovery_dns_SUITE). + +-include_lib("common_test/include/ct.hrl"). +-include_lib("amqp_client/include/amqp_client.hrl"). +-include_lib("eunit/include/eunit.hrl"). + +-compile(export_all). + +all() -> + [ + {group, non_parallel} + ]. + +groups() -> + [ + {non_parallel, [], [ + hostname_discovery_with_long_node_names, + hostname_discovery_with_short_node_names, + node_discovery_with_long_node_names, + node_discovery_with_short_node_names + ]} + ]. + +suite() -> + [ + %% If a test hangs, no need to wait for 30 minutes. + {timetrap, {minutes, 1}} + ]. + + +%% ------------------------------------------------------------------- +%% Testsuite setup/teardown. +%% ------------------------------------------------------------------- + +init_per_suite(Config) -> + rabbit_ct_helpers:log_environment(), + rabbit_ct_helpers:run_setup_steps(Config). + +end_per_suite(Config) -> + rabbit_ct_helpers:run_teardown_steps(Config). + + +%% ------------------------------------------------------------------- +%% Test cases +%% ------------------------------------------------------------------- + +%% peer_discovery.tests.rabbitmq.net used in the tests below +%% returns three A records two of which fail our resolution process: +%% +%% * One does not resolve to a [typically] non-reachable IP +%% * One does not support reverse lookup queries + +-define(DISCOVERY_ENDPOINT, "peer_discovery.tests.rabbitmq.net"). + +hostname_discovery_with_long_node_names(_) -> + Result = rabbit_peer_discovery_dns:discover_hostnames(?DISCOVERY_ENDPOINT, true), + ?assertEqual(["www.rabbitmq.com"], Result). + +hostname_discovery_with_short_node_names(_) -> + Result = rabbit_peer_discovery_dns:discover_hostnames(?DISCOVERY_ENDPOINT, false), + ?assertEqual(["www"], Result). + +node_discovery_with_long_node_names(_) -> + Result = rabbit_peer_discovery_dns:discover_nodes(?DISCOVERY_ENDPOINT, true), + ?assertEqual(["ct_rabbit@www.rabbitmq.com"], Result). + +node_discovery_with_short_node_names(_) -> + Result = rabbit_peer_discovery_dns:discover_nodes(?DISCOVERY_ENDPOINT, false), + ?assertEqual(["ct_rabbit@www"], Result). |
