Skip to content

Commit

Permalink
Merge pull request #10134 from rabbitmq/mergify/bp/v3.12.x/pr-10133
Browse files Browse the repository at this point in the history
Fix types and tests in peer discovery (backport #10133)
  • Loading branch information
michaelklishin authored Dec 13, 2023
2 parents cd7f1f9 + 2f0d6c7 commit 627576d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
10 changes: 5 additions & 5 deletions deps/rabbitmq_peer_discovery_aws/test/unit_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,27 @@ maybe_add_tag_filters(_Config) ->
?assertEqual(Expectation, Result).

get_hostname_name_from_reservation_set(_Config) ->
{
ok = eunit:test({
foreach,
fun on_start/0,
fun on_finish/1,
[{"from private DNS",
fun() ->
Expectation = ["ip-10-0-16-31.eu-west-1.compute.internal",
"ip-10-0-16-29.eu-west-1.compute.internal"],
Expectation = ["ip-10-0-16-29.eu-west-1.compute.internal",
"ip-10-0-16-31.eu-west-1.compute.internal"],
?assertEqual(Expectation,
rabbit_peer_discovery_aws:get_hostname_name_from_reservation_set(
reservation_set(), []))
end},
{"from private IP",
fun() ->
os:putenv("AWS_USE_PRIVATE_IP", "true"),
Expectation = ["10.0.16.31", "10.0.16.29"],
Expectation = ["10.0.16.29", "10.0.16.31"],
?assertEqual(Expectation,
rabbit_peer_discovery_aws:get_hostname_name_from_reservation_set(
reservation_set(), []))
end}]
}.
}).

registration_support(_Config) ->
?assertEqual(false, rabbit_peer_discovery_aws:supports_registration()).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
% by `httpc`
-define(DEFAULT_HTTP_TIMEOUT, 2250).

-type peer_discovery_config_value() :: atom() | integer() | string() | list() | map() | any() | undefined.
-type peer_discovery_config_value() :: port()
| atom()
| integer()
| string()
| proplists:proplist()
| map()
| list()
| undefined.

-record(peer_discovery_config_entry_meta,
{env_variable :: string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ get_integer_from_env_variable_or_map(Map, OSKey, AppKey, Default) ->
%%--------------------------------------------------------------------
-spec normalize(Type :: atom(),
Value :: atom() | boolean() | integer() | string() | list()) ->
atom() | integer() | string().
peer_discovery_config_value().
%% TODO: switch these to use delegate to rabbit_data_coercion:*
normalize(Type, Value) when Type =:= port ->
rabbit_peer_discovery_util:parse_port(Value);
normalize(Type, Value) when Type =:= atom ->
rabbit_peer_discovery_util:as_atom(Value);
normalize(Type, Value) when Type =:= list ->
rabbit_data_coercion:to_list(Value);
rabbit_peer_discovery_util:as_list(Value);
normalize(Type, Value) when Type =:= integer ->
rabbit_peer_discovery_util:as_integer(Value);
normalize(Type, Value) when Type =:= string ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,18 @@ as_list([]) -> [];
as_list(Value) when is_atom(Value) ; is_integer(Value) ; is_binary(Value) ->
[Value];
as_list(Value) when is_list(Value) ->
Parse = fun(T) ->
S = string:strip(T),
case string:to_float(S) of
{Float, []} -> Float;
_ -> case string:to_integer(S) of
{Integer, []} -> Integer;
_ -> S
end
end
end,
case io_lib:printable_list(Value) or io_lib:printable_unicode_list(Value) of
true -> [case string:to_float(S) of
{Float, []} -> Float;
_ -> case string:to_integer(S) of
{Integer, []} -> Integer;
_ -> string:strip(S)
end
end || S <- string:tokens(Value, ",")];
true -> [Parse(T) || T <- string:tokens(Value, ",")];
false -> Value
end;
as_list(Value) ->
Expand Down

0 comments on commit 627576d

Please # to comment.