Skip to content

Commit

Permalink
Add address_please_returns_ip_fallbacks_to_resolve testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Nov 28, 2023
1 parent 4c2a9ff commit f8452ee
Showing 1 changed file with 55 additions and 32 deletions.
87 changes: 55 additions & 32 deletions big_tests/tests/cets_disco_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ rdbms_cases() ->
no_ip_in_db,
cannot_connect_to_epmd,
address_please,
address_please_returns_ip].
address_please_returns_ip,
address_please_returns_ip_fallbacks_to_resolve].

suite() ->
distributed_helper:require_rpc_nodes([mim, mim2]).
Expand Down Expand Up @@ -58,45 +59,22 @@ end_per_group(_, Config) ->
Config.

init_per_testcase(address_please_returns_ip, Config) ->
case rpc(mim(), erlang, whereis, [mongoose_cets_discovery]) of
undefined ->
mock_epmd(mim()),
{ok, _} = rpc(mim(), supervisor, start_child, [ejabberd_sup, cets_disco_spec(<<"testmim1@localhost">>, <<"127.0.0.2">>)]),
{ok, _} = rpc(mim2(), supervisor, start_child, [ejabberd_sup, cets_disco_spec(<<"testmim2@localhost">>, <<"127.0.0.5">>)]),
%% Force nodes to see each other
rpc(mim2(), erlang, send, [mongoose_cets_discovery, check]),
ok = rpc(mim2(), cets_discovery, wait_for_get_nodes, [mongoose_cets_discovery, 5000]),
rpc(mim(), erlang, send, [mongoose_cets_discovery, check]),
Config;
_ ->
{skip, cets_disco_already_running}
end;
start_cets_discovery(Config, true);
init_per_testcase(address_please_returns_ip_fallbacks_to_resolve, Config) ->
start_cets_discovery(Config, false);
init_per_testcase(_CaseName, Config) -> Config.

end_per_testcase(address_please_returns_ip, Config) ->
ok = rpc(mim(), supervisor, terminate_child, [ejabberd_sup, cets_discovery]),
ok = rpc(mim2(), supervisor, terminate_child, [ejabberd_sup, cets_discovery]),
stop_cets_discovery(),
unmock_epmd(mim()),
Config;
end_per_testcase(address_please_returns_ip_fallbacks_to_resolve, Config) ->
stop_cets_discovery(),
Config;
end_per_testcase(_CaseName, Config) ->
unmock(mim()),
unmock(mim2()).

cets_disco_spec(Node, IP) ->
DiscoOpts = #{
backend_module => mongoose_cets_discovery_rdbms,
cluster_name => <<"mim">>,
node_name_to_insert => Node,
node_ip_binary => IP,
name => mongoose_cets_discovery},
#{
id => cets_discovery,
start => {mongoose_cets_discovery, start_link, [DiscoOpts]},
restart => temporary,
type => worker,
shutdown => infinity,
modules => [cets_discovery]}.

%%--------------------------------------------------------------------
%% Test cases
%%--------------------------------------------------------------------
Expand Down Expand Up @@ -254,7 +232,13 @@ address_please_returns_ip(Config) ->
Res = rpc(mim(), mongoose_epmd, address_please, ["testmim2", "localhost", inet]),
Info = rpc(mim(), cets_discovery, system_info, [mongoose_cets_discovery]),
ct:log("system_info ~p", [Info]),
{ok, {127, 0, 0, 5}} = Res.
{ok, {192, 168, 115, 112}} = Res.

address_please_returns_ip_fallbacks_to_resolve(Config) ->
Res = rpc(mim(), mongoose_epmd, address_please, ["testmim2", "localhost", inet]),
Info = rpc(mim(), cets_discovery, system_info, [mongoose_cets_discovery]),
ct:log("system_info ~p", [Info]),
{ok, {127, 0, 0, 1}} = Res.

%%--------------------------------------------------------------------
%% Helpers
Expand Down Expand Up @@ -348,3 +332,42 @@ start_node_address_server(Node) ->

stop_node_address_server(Node) ->
rpc(Node, supervisor, terminate_child, [ejabberd_sup, mongoose_node_address]).

start_cets_discovery(Config, MockEpmd) ->
case rpc(mim(), erlang, whereis, [mongoose_cets_discovery]) of
undefined ->
case MockEpmd of
true ->
mock_epmd(mim());
false ->
ok
end,
{ok, _} = rpc(mim(), supervisor, start_child, [ejabberd_sup, cets_disco_spec(<<"testmim1@localhost">>, <<"192.168.115.111">>)]),
{ok, _} = rpc(mim2(), supervisor, start_child, [ejabberd_sup, cets_disco_spec(<<"testmim2@localhost">>, <<"192.168.115.112">>)]),
%% Force nodes to see each other
rpc(mim2(), erlang, send, [mongoose_cets_discovery, check]),
ok = rpc(mim2(), cets_discovery, wait_for_get_nodes, [mongoose_cets_discovery, 5000]),
rpc(mim(), erlang, send, [mongoose_cets_discovery, check]),
Config;
_ ->
{skip, cets_disco_already_running}
end.

stop_cets_discovery() ->
ok = rpc(mim(), supervisor, terminate_child, [ejabberd_sup, cets_discovery]),
ok = rpc(mim2(), supervisor, terminate_child, [ejabberd_sup, cets_discovery]).

cets_disco_spec(Node, IP) ->
DiscoOpts = #{
backend_module => mongoose_cets_discovery_rdbms,
cluster_name => <<"mim">>,
node_name_to_insert => Node,
node_ip_binary => IP,
name => mongoose_cets_discovery},
#{
id => cets_discovery,
start => {mongoose_cets_discovery, start_link, [DiscoOpts]},
restart => temporary,
type => worker,
shutdown => infinity,
modules => [cets_discovery]}.

0 comments on commit f8452ee

Please sign in to comment.