-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom epmd module - simple solution #4179
Changes from 9 commits
d4cbade
09c8b9d
94eb76c
c865c54
5039a80
aa68685
fc3500f
4c2a9ff
f8452ee
b8ec9b3
39a0742
e7e9230
408b3a4
dad1fbf
1627994
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,14 @@ rdbms_cases() -> | |
[rdbms_backend, | ||
rdbms_backend_supports_auto_cleaning, | ||
rdbms_backend_node_doesnt_remove_itself, | ||
rdbms_backend_db_queries]. | ||
rdbms_backend_db_queries, | ||
rdbms_backend_publishes_node_ip, | ||
no_record_for_node, | ||
no_ip_in_db, | ||
cannot_connect_to_epmd, | ||
address_please, | ||
address_please_returns_ip, | ||
address_please_returns_ip_fallbacks_to_resolve]. | ||
|
||
suite() -> | ||
distributed_helper:require_rpc_nodes([mim, mim2]). | ||
|
@@ -34,6 +41,8 @@ suite() -> | |
%%-------------------------------------------------------------------- | ||
|
||
init_per_group(rdbms, Config) -> | ||
start_node_address_server(mim()), | ||
start_node_address_server(mim2()), | ||
case not ct_helper:is_ct_running() | ||
orelse mongoose_helper:is_rdbms_enabled(domain_helper:host_type()) of | ||
false -> {skip, rdbms_or_ct_not_running}; | ||
|
@@ -42,11 +51,26 @@ init_per_group(rdbms, Config) -> | |
init_per_group(_, Config) -> | ||
Config. | ||
|
||
end_per_group(rdbms, Config) -> | ||
stop_node_address_server(mim()), | ||
stop_node_address_server(mim2()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgot to remove? |
||
Config; | ||
end_per_group(_, Config) -> | ||
Config. | ||
|
||
init_per_testcase(address_please_returns_ip, Config) -> | ||
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) -> | ||
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()). | ||
|
@@ -144,24 +168,77 @@ rdbms_backend_db_queries(_Config) -> | |
TS2 = TS + 100, | ||
|
||
%% insertion fails if node name or node num is already added for the cluster | ||
?assertEqual({updated, 1}, insert_new(CN, <<"test1">>, TS, 1)), | ||
?assertMatch({error, _}, insert_new(CN, <<"test1">>, TS, 1)), | ||
?assertMatch({error, _}, insert_new(CN, <<"test1">>, TS, 2)), | ||
?assertMatch({error, _}, insert_new(CN, <<"test2">>, TS, 1)), | ||
?assertEqual({updated, 1}, insert_new(CN, <<"test2">>, TS, 2)), | ||
?assertEqual({updated, 1}, insert_new(CN, <<"test1">>, 1, <<>>, TS)), | ||
?assertMatch({error, _}, insert_new(CN, <<"test1">>, 1, <<>>, TS)), | ||
?assertMatch({error, _}, insert_new(CN, <<"test1">>, 2, <<>>, TS)), | ||
?assertMatch({error, _}, insert_new(CN, <<"test2">>, 1, <<>>, TS)), | ||
?assertEqual({updated, 1}, insert_new(CN, <<"test2">>, 2, <<>>, TS)), | ||
|
||
%% update of the timestamp works correctly | ||
{selected, SelectedNodes1} = select(CN), | ||
?assertEqual(lists:sort([{<<"test1">>, 1, TS}, {<<"test2">>, 2, TS}]), | ||
?assertEqual(lists:sort([{<<"test1">>, 1, <<>>, TS}, {<<"test2">>, 2, <<>>, TS}]), | ||
lists:sort(SelectedNodes1)), | ||
?assertEqual({updated, 1}, update_existing(CN, <<"test1">>, TS2)), | ||
?assertEqual({updated, 1}, update_existing(CN, <<"test1">>, <<>>, TS2)), | ||
{selected, SelectedNodes2} = select(CN), | ||
?assertEqual(lists:sort([{<<"test1">>, 1, TS2}, {<<"test2">>, 2, TS}]), | ||
?assertEqual(lists:sort([{<<"test1">>, 1, <<>>, TS2}, {<<"test2">>, 2, <<>>, TS}]), | ||
lists:sort(SelectedNodes2)), | ||
|
||
%% node removal work correctly | ||
?assertEqual({updated, 1}, delete_node_from_db(CN, <<"test1">>)), | ||
?assertEqual({selected, [{<<"test2">>, 2, TS}]}, select(CN)). | ||
?assertEqual({selected, [{<<"test2">>, 2, <<>>, TS}]}, select(CN)). | ||
|
||
rdbms_backend_publishes_node_ip(_Config) -> | ||
%% get_pairs would return only real available nodes, so use the real node names | ||
Node1b = atom_to_binary(maps:get(node, mim())), | ||
Node2b = atom_to_binary(maps:get(node, mim2())), | ||
CN = random_cluster_name(?FUNCTION_NAME), | ||
Opts1 = #{cluster_name => CN, node_name_to_insert => Node1b, | ||
node_ip_binary => <<"127.0.0.1">>}, | ||
Opts2 = #{cluster_name => CN, node_name_to_insert => Node2b, | ||
node_ip_binary => <<"127.0.0.1">>}, | ||
State1 = disco_init(mim(), Opts1), | ||
State2 = disco_init(mim2(), Opts2), | ||
{{ok, _Nodes1_2}, State1_2} = disco_get_nodes(mim(), State1), | ||
{{ok, _Nodes2_2}, State2_2} = disco_get_nodes(mim2(), State2), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should already see the entry from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, I guess |
||
{{ok, _Nodes1_3}, State1_3} = disco_get_nodes(mim(), State1_2), | ||
{{ok, _Nodes2_3}, State2_3} = disco_get_nodes(mim2(), State2_2), | ||
{ok, {127, 0, 0, 1}} = match_node_name(mim2(), State2_3, Node1b), | ||
{ok, {127, 0, 0, 1}} = match_node_name(mim(), State1_3, Node2b). | ||
|
||
no_record_for_node(_Config) -> | ||
Node = <<"mongoose@badhost">>, | ||
BackState = #{address_pairs => #{}}, | ||
{error, {no_record_for_node, Node}} = match_node_name(mim(), BackState, Node), | ||
ok. | ||
|
||
no_ip_in_db(_Config) -> | ||
Node = <<"mongoose@noiphost">>, | ||
BackState = #{address_pairs => #{Node => <<>>}}, | ||
{error, {no_ip_in_db, Node}} = match_node_name(mim(), BackState, Node), | ||
ok. | ||
|
||
cannot_connect_to_epmd(_Config) -> | ||
Node = <<"mongoose@noepmdhost">>, | ||
%% IP from a test range | ||
BackState = #{address_pairs => #{Node => <<"192.0.2.1">>}}, | ||
{error, {cannot_connect_to_epmd, Node, {192, 0, 2, 1}}} = match_node_name(mim(), BackState, Node), | ||
ok. | ||
|
||
address_please(_Config) -> | ||
{error, nxdomain} = | ||
rpc(mim(), mongoose_epmd, address_please, ["mongooseim", "badbadhost", inet]). | ||
|
||
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, {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 | ||
|
@@ -177,6 +254,9 @@ disco_get_nodes(Node, State) -> | |
log_disco_request(?FUNCTION_NAME, Node, State, NewState), | ||
NewState. | ||
|
||
match_node_name(Node, SysInfo, NodeToLookup) -> | ||
rpc(Node, mongoose_epmd, match_node_name, [SysInfo, NodeToLookup]). | ||
|
||
log_disco_request(disco_init, Node, #{cluster_name := CN} = Opts, State) -> | ||
ct:log("[0] disco_init(~p,~n" ++ | ||
" ~p) =~n" ++ | ||
|
@@ -209,29 +289,85 @@ mock_timestamp(Node, Timestamp) -> | |
unmock_timestamp(Node) -> | ||
ok = rpc(Node, meck, unload, [mongoose_rdbms_timestamp]). | ||
|
||
mock_epmd(Node) -> | ||
ok = rpc(Node, meck, new, [mongoose_epmd, [passthrough, no_link]]), | ||
ok = rpc(Node, meck, expect, [mongoose_epmd, can_connect, 1, true]), | ||
%% Ensure that we mock | ||
true = rpc(Node, mongoose_epmd, can_connect, [{192, 168, 0, 100}]). | ||
|
||
unmock_epmd(Node) -> | ||
ok = rpc(Node, meck, unload, [mongoose_epmd]). | ||
|
||
unmock(Node) -> | ||
rpc(Node, meck, unload, []). | ||
|
||
random_cluster_name(CaseName) -> | ||
Rand = rpc(mim(), mongoose_bin, gen_from_crypto, []), | ||
<<"big_test_", (atom_to_binary(CaseName))/binary, "_", Rand/binary>>. | ||
|
||
insert_new(CN, BinNode, TS, NodeNum) -> | ||
Ret = rpc(mim(), mongoose_cets_discovery_rdbms, insert_new, [CN, BinNode, TS, NodeNum]), | ||
ct:log("insert_new(~p, ~p, ~p, ~p) = ~p", [CN, BinNode, TS, NodeNum, Ret]), | ||
insert_new(CN, BinNode, NodeNum, Address, TS) -> | ||
Ret = rpc(mim(), mongoose_cets_discovery_rdbms, insert_new, [CN, BinNode, NodeNum, Address, TS]), | ||
ct:log("insert_new(~p, ~p, ~p, ~p, ~p) = ~p", [CN, BinNode, NodeNum, Address, TS, Ret]), | ||
Ret. | ||
|
||
select(CN) -> | ||
Ret = rpc(mim(), mongoose_cets_discovery_rdbms, select, [CN]), | ||
ct:log("select(~p) = ~p", [CN, Ret]), | ||
Ret. | ||
|
||
update_existing(CN, BinNode, TS) -> | ||
Ret = rpc(mim(), mongoose_cets_discovery_rdbms, update_existing, [CN, BinNode, TS]), | ||
ct:log("select(~p, ~p, ~p) = ~p", [CN, BinNode, TS, Ret]), | ||
update_existing(CN, BinNode, Address, TS) -> | ||
Ret = rpc(mim(), mongoose_cets_discovery_rdbms, update_existing, [CN, BinNode, Address, TS]), | ||
ct:log("select(~p, ~p, ~p, ~p) = ~p", [CN, BinNode, Address, TS, Ret]), | ||
Ret. | ||
|
||
delete_node_from_db(CN, BinNode) -> | ||
Ret = rpc(mim(), mongoose_cets_discovery_rdbms, delete_node_from_db, [CN, BinNode]), | ||
ct:log("delete_node_from_db(~p, ~p) = ~p", [CN, BinNode, Ret]), | ||
Ret. | ||
|
||
start_node_address_server(Node) -> | ||
MFA = {mongoose_node_address, start_link, []}, | ||
ChildSpec = #{id => mongoose_node_address, start => MFA, restart => temporary}, | ||
rpc(Node, supervisor, start_child, [ejabberd_sup, ChildSpec]). | ||
|
||
stop_node_address_server(Node) -> | ||
rpc(Node, supervisor, terminate_child, [ejabberd_sup, mongoose_node_address]). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgot to remove? |
||
|
||
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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is strange, because we will skip cets-specific tests in the |
||
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]}. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,5 @@ | |
|
||
## Tweak GC to run more often | ||
-env ERL_FULLSWEEP_AFTER 2 | ||
|
||
{{epmd_vm_args}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will need to document this option. Maybe it should be enabled by default (but then we need to make sure it doesn't break without CETS). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to remove?