From f8452ee0245ac5a9459e0c8153d2971b3624e136 Mon Sep 17 00:00:00 2001 From: Mikhail Uvarov Date: Tue, 28 Nov 2023 19:37:14 +0100 Subject: [PATCH] Add address_please_returns_ip_fallbacks_to_resolve testcase --- big_tests/tests/cets_disco_SUITE.erl | 87 ++++++++++++++++++---------- 1 file changed, 55 insertions(+), 32 deletions(-) diff --git a/big_tests/tests/cets_disco_SUITE.erl b/big_tests/tests/cets_disco_SUITE.erl index 6a720e23df..7646571d25 100644 --- a/big_tests/tests/cets_disco_SUITE.erl +++ b/big_tests/tests/cets_disco_SUITE.erl @@ -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]). @@ -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 %%-------------------------------------------------------------------- @@ -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 @@ -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]}.