Skip to content

Commit 627576d

Browse files
Merge pull request #10134 from rabbitmq/mergify/bp/v3.12.x/pr-10133
Fix types and tests in peer discovery (backport #10133)
2 parents cd7f1f9 + 2f0d6c7 commit 627576d

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

deps/rabbitmq_peer_discovery_aws/test/unit_SUITE.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,27 @@ maybe_add_tag_filters(_Config) ->
4848
?assertEqual(Expectation, Result).
4949

5050
get_hostname_name_from_reservation_set(_Config) ->
51-
{
51+
ok = eunit:test({
5252
foreach,
5353
fun on_start/0,
5454
fun on_finish/1,
5555
[{"from private DNS",
5656
fun() ->
57-
Expectation = ["ip-10-0-16-31.eu-west-1.compute.internal",
58-
"ip-10-0-16-29.eu-west-1.compute.internal"],
57+
Expectation = ["ip-10-0-16-29.eu-west-1.compute.internal",
58+
"ip-10-0-16-31.eu-west-1.compute.internal"],
5959
?assertEqual(Expectation,
6060
rabbit_peer_discovery_aws:get_hostname_name_from_reservation_set(
6161
reservation_set(), []))
6262
end},
6363
{"from private IP",
6464
fun() ->
6565
os:putenv("AWS_USE_PRIVATE_IP", "true"),
66-
Expectation = ["10.0.16.31", "10.0.16.29"],
66+
Expectation = ["10.0.16.29", "10.0.16.31"],
6767
?assertEqual(Expectation,
6868
rabbit_peer_discovery_aws:get_hostname_name_from_reservation_set(
6969
reservation_set(), []))
7070
end}]
71-
}.
71+
}).
7272

7373
registration_support(_Config) ->
7474
?assertEqual(false, rabbit_peer_discovery_aws:supports_registration()).

deps/rabbitmq_peer_discovery_common/include/rabbit_peer_discovery.hrl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@
1616
% by `httpc`
1717
-define(DEFAULT_HTTP_TIMEOUT, 2250).
1818

19-
-type peer_discovery_config_value() :: atom() | integer() | string() | list() | map() | any() | undefined.
19+
-type peer_discovery_config_value() :: port()
20+
| atom()
21+
| integer()
22+
| string()
23+
| proplists:proplist()
24+
| map()
25+
| list()
26+
| undefined.
2027

2128
-record(peer_discovery_config_entry_meta,
2229
{env_variable :: string(),

deps/rabbitmq_peer_discovery_common/src/rabbit_peer_discovery_config.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ get_integer_from_env_variable_or_map(Map, OSKey, AppKey, Default) ->
120120
%%--------------------------------------------------------------------
121121
-spec normalize(Type :: atom(),
122122
Value :: atom() | boolean() | integer() | string() | list()) ->
123-
atom() | integer() | string().
123+
peer_discovery_config_value().
124124
%% TODO: switch these to use delegate to rabbit_data_coercion:*
125125
normalize(Type, Value) when Type =:= port ->
126126
rabbit_peer_discovery_util:parse_port(Value);
127127
normalize(Type, Value) when Type =:= atom ->
128128
rabbit_peer_discovery_util:as_atom(Value);
129129
normalize(Type, Value) when Type =:= list ->
130-
rabbit_data_coercion:to_list(Value);
130+
rabbit_peer_discovery_util:as_list(Value);
131131
normalize(Type, Value) when Type =:= integer ->
132132
rabbit_peer_discovery_util:as_integer(Value);
133133
normalize(Type, Value) when Type =:= string ->

deps/rabbitmq_peer_discovery_common/src/rabbit_peer_discovery_util.erl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,18 @@ as_list([]) -> [];
410410
as_list(Value) when is_atom(Value) ; is_integer(Value) ; is_binary(Value) ->
411411
[Value];
412412
as_list(Value) when is_list(Value) ->
413+
Parse = fun(T) ->
414+
S = string:strip(T),
415+
case string:to_float(S) of
416+
{Float, []} -> Float;
417+
_ -> case string:to_integer(S) of
418+
{Integer, []} -> Integer;
419+
_ -> S
420+
end
421+
end
422+
end,
413423
case io_lib:printable_list(Value) or io_lib:printable_unicode_list(Value) of
414-
true -> [case string:to_float(S) of
415-
{Float, []} -> Float;
416-
_ -> case string:to_integer(S) of
417-
{Integer, []} -> Integer;
418-
_ -> string:strip(S)
419-
end
420-
end || S <- string:tokens(Value, ",")];
424+
true -> [Parse(T) || T <- string:tokens(Value, ",")];
421425
false -> Value
422426
end;
423427
as_list(Value) ->

0 commit comments

Comments
 (0)