1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
%% This Source Code Form is subject to the terms of the Mozilla Public
%% License, v. 2.0. If a copy of the MPL was not distributed with this
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%
%% Copyright (c) 2011-2020 VMware, Inc. or its affiliates. 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,
test_aaaa_record_hostname_discovery
]}
].
suite() ->
[
%% If a test hangs, no need to wait for 30 minutes.
{timetrap, {minutes, 1}}
].
%% -------------------------------------------------------------------
%% Testsuite setup/teardown.
%% -------------------------------------------------------------------
%% These are stable, publicly resolvable hostnames that
%% both return A and AAAA records that reverse resolve.
-define(DISCOVERY_ENDPOINT_RECORD_A, "dns.google").
-define(DISCOVERY_ENDPOINT_RECORD_AAAA, "dns.google").
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).
init_per_testcase(test_aaaa_record, Config) ->
case inet_res:lookup(?DISCOVERY_ENDPOINT_RECORD_AAAA, in, aaaa) of
[] ->
{skip, "pre-configured AAAA record does not resolve, skipping"};
[_ | _] ->
Config
end;
init_per_testcase(_Testcase, Config) ->
case inet_res:lookup(?DISCOVERY_ENDPOINT_RECORD_A, in, a) of
[] ->
{skip, "pre-configured *.rabbitmq.com record does not resolve, skipping"};
[_ | _] ->
Config
end.
end_per_testcase(_Testcase, Config) ->
case inet_res:lookup(?DISCOVERY_ENDPOINT_RECORD_A, in, a) of
[] ->
{skip, "pre-configured *.rabbitmq.com record does not resolve, skipping"};
[_ | _] ->
Config
end.
%% -------------------------------------------------------------------
%% Test cases
%% -------------------------------------------------------------------
test_aaaa_record_hostname_discovery(_) ->
Result = rabbit_peer_discovery_dns:discover_hostnames(?DISCOVERY_ENDPOINT_RECORD_AAAA, true),
?assert(string:str(lists:flatten(Result), "dns.google") > 0).
hostname_discovery_with_long_node_names(_) ->
Result = rabbit_peer_discovery_dns:discover_hostnames(?DISCOVERY_ENDPOINT_RECORD_A, true),
?assert(lists:member("dns.google", Result)).
hostname_discovery_with_short_node_names(_) ->
Result = rabbit_peer_discovery_dns:discover_hostnames(?DISCOVERY_ENDPOINT_RECORD_A, false),
?assert(lists:member("dns", Result)).
node_discovery_with_long_node_names(_) ->
Result = rabbit_peer_discovery_dns:discover_nodes(?DISCOVERY_ENDPOINT_RECORD_A, true),
?assert(lists:member('ct_rabbit@dns.google', Result)).
node_discovery_with_short_node_names(_) ->
Result = rabbit_peer_discovery_dns:discover_nodes(?DISCOVERY_ENDPOINT_RECORD_A, false),
?assert(lists:member(ct_rabbit@dns, Result)).
|