Skip to content
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

Start cover on mim1 instead of the CT node #4336

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 41 additions & 25 deletions big_tests/run_common_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,19 @@ prepare(Props) ->
maybe_compile_cover([]) ->
io:format("cover: skip cover compilation~n", []),
ok;
maybe_compile_cover(Nodes) ->
maybe_compile_cover([CoverNode|_] = Nodes) ->
io:format("cover: compiling modules for nodes ~p~n", [Nodes]),
import_code_paths(hd(Nodes)),

cover:start(Nodes),
%% We use mim1 as a main node.
%% Only the main node supports meck
%% (other nodes should not use meck for the cover compiled modules).
{ok, _} = rpc:call(CoverNode, cover, start, [Nodes]),
Dir = call(hd(Nodes), code, lib_dir, [mongooseim, ebin]),

%% Time is in microseconds
{Time, Compiled} = timer:tc(fun() ->
Results = cover:compile_beam_directory(Dir),
Results = cover_compile_dir(CoverNode, Dir),
Ok = [X || X = {ok, _} <- Results],
NotOk = Results -- Ok,
#{ok => length(Ok), failed => NotOk}
Expand All @@ -391,20 +394,19 @@ analyze(Props, CoverOpts) ->

analyze(_Props, _CoverOpts, []) ->
ok;
analyze(_Props, CoverOpts, Nodes) ->
deduplicate_cover_server_console_prints(),
analyze(_Props, CoverOpts, [CoverNode|_] = Nodes) ->
%% Import small tests cover
Files = filelib:wildcard(repo_dir() ++ "/_build/**/cover/*.coverdata"),
io:format("Files: ~p", [Files]),
report_time("Import cover data into run_common_test node", fun() ->
[cover:import(File) || File <- Files]
[cover_import(CoverNode, File) || File <- Files]
end),
report_time("Export merged cover data", fun() ->
cover:export("/tmp/mongoose_combined.coverdata")
cover_export(CoverNode, "/tmp/mongoose_combined.coverdata")
end),
case os:getenv("GITHUB_RUN_ID") of
false ->
make_html(modules_to_analyze(CoverOpts));
make_html(CoverNode, modules_to_analyze(CoverNode, CoverOpts));
_ ->
ok
end,
Expand All @@ -414,11 +416,11 @@ analyze(_Props, CoverOpts, Nodes) ->
ok;
_ ->
report_time("Stopping cover on MongooseIM nodes", fun() ->
cover:stop([node()|Nodes])
cover_stop(CoverNode, Nodes)
end)
end.

make_html(Modules) ->
make_html(CoverNode, Modules) ->
{ok, Root} = file:get_cwd(),
SortScript = Root ++ "/priv/sorttable.js",
os:cmd("cp " ++ SortScript ++ " " ++ ?CT_REPORT),
Expand All @@ -437,11 +439,11 @@ make_html(Modules) ->
FileName = lists:flatten(io_lib:format("~s.COVER.html",[Module])),

%% We assume that import_code_paths/1 was called earlier
case cover:analyse(Module, module) of
case cover_analyse(CoverNode, Module) of
{ok, {Module, {C, NC}}} ->
file:write(File, row(atom_to_list(Module), C, NC, percent(C,NC),"coverage/"++FileName)),
FilePathC = filename:join([CoverageDir, FileName]),
catch cover:analyse_to_file(Module, FilePathC, [html]),
cover_analyse_to_html_file(CoverNode, Module, FilePathC),
{CAcc + C, NCAcc + NC};
Reason ->
error_logger:error_msg("issue=cover_analyse_failed module=~p reason=~p",
Expand Down Expand Up @@ -503,9 +505,9 @@ module_list(undefined) ->
module_list(ModuleList) ->
[ list_to_atom(L) || L <- string:tokens(ModuleList, ", ") ].

modules_to_analyze(true) ->
lists:usort(cover:imported_modules() ++ cover:modules());
modules_to_analyze(ModuleList) when is_list(ModuleList) ->
modules_to_analyze(CoverNode, true) ->
lists:usort(cover_all_modules(CoverNode));
modules_to_analyze(_CoverNode, ModuleList) when is_list(ModuleList) ->
ModuleList.

add({X1, X2, X3, X4},
Expand Down Expand Up @@ -630,16 +632,6 @@ handle_file_error(_FileName, Other) ->

%% ------------------------------------------------------------------

%% cover_server process is using io:format too much.
%% This code removes duplicate io:formats.
%%
%% Example of a message we want to write only once:
%% "Analysis includes data from imported files" from cover.erl in Erlang/R19
deduplicate_cover_server_console_prints() ->
%% Set a new group leader for cover_server
CoverPid = whereis(cover_server),
dedup_proxy_group_leader:start_proxy_group_leader_for(CoverPid).

ct_run_dirs() ->
filelib:wildcard("ct_report/ct_run*").

Expand Down Expand Up @@ -721,3 +713,27 @@ assert_preset_present(Preset, PresetConfs) ->
error_logger:error_msg("Preset not found ~p~n", [Preset]),
error({preset_not_found, Preset})
end.

cover_stop(CoverNode, Nodes) ->
cover_call(CoverNode, stop, [Nodes]).

cover_all_modules(CoverNode) ->
cover_call(CoverNode, imported_modules, []) ++ rpc:call(CoverNode, cover, modules, []).

cover_analyse_to_html_file(CoverNode, Module, FilePathC) ->
catch cover_call(CoverNode, analyse_to_file, [Module, FilePathC, [html]]).

cover_analyse(CoverNode, Module) ->
cover_call(CoverNode, analyse, [Module, module]).

cover_export(CoverNode, ToFile) ->
cover_call(CoverNode, export, [ToFile]).

cover_import(CoverNode, FromFile) ->
cover_call(CoverNode, import, [FromFile]).

cover_compile_dir(CoverNode, Dir) ->
cover_call(CoverNode, compile_beam_directory, [Dir]).

cover_call(CoverNode, Fun, Args) ->
rpc:call(node(), cover, Fun, Args).
73 changes: 0 additions & 73 deletions big_tests/src/dedup_proxy_group_leader.erl

This file was deleted.

3 changes: 1 addition & 2 deletions big_tests/tests/cets_disco_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ end_per_testcase(Name, Config) when Name == address_please_returns_ip;
stop_cets_discovery(),
Config;
end_per_testcase(_CaseName, _Config) ->
unmock(mim()),
unmock(mim2()).
unmock(mim()).

%%--------------------------------------------------------------------
%% Test cases
Expand Down
23 changes: 22 additions & 1 deletion big_tests/tests/graphql_cets_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

-compile([export_all, nowarn_export_all]).

-import(distributed_helper, [mim/0, mim2/0, rpc/4]).
-import(distributed_helper, [mim/0, mim2/0, reg/0, rpc/4]).
-import(domain_helper, [host_type/1]).
-import(mongooseimctl_helper, [rpc_call/3]).
-import(graphql_helper, [execute_command/4, get_unauthorized/1, get_ok_value/2, get_not_loaded/1]).
Expand Down Expand Up @@ -44,6 +44,7 @@ cets_not_configured_test() ->
get_system_info_not_configured_test].

init_per_suite(Config) ->
block_node(),
case rpc_call(mongoose_config, get_opt, [[internal_databases, cets, backend], undefined]) of
rdbms ->
Config1 = escalus:init_per_suite(Config),
Expand All @@ -56,6 +57,7 @@ init_per_suite(Config) ->
end.

end_per_suite(Config) ->
unblock_node(),
case rpc_call(mongoose_config, lookup_opt, [[internal_databases, cets, backend]]) of
{ok, rdbms} ->
ensure_bad_node_unregistered(),
Expand All @@ -64,6 +66,25 @@ end_per_suite(Config) ->
ok
end.

block_node() ->
%% Cover at mim1 node connects to otherrnodes but it causes reg1 node to be listed
%% in confict_tables/conflict_nodes.
%% Reg is undefined for dynamic domains (so we use try..catch).
try reg() of
#{node := Reg1} ->
rpc(mim(), erlang, set_cookie, [Reg1, badbadcookie]),
rpc(mim(), erlang, disconnect_node, [Reg1]),
mongoose_helper:wait_until(fun() -> lists:member(Reg1, rpc(mim(), erlang, nodes, [])) end, false)
catch _:_ -> ok
end.

unblock_node() ->
try reg() of
#{node := Reg1} ->
rpc(mim(), erlang, set_cookie, [Reg1, rpc(mim(), erlang, get_cookie, [])])
catch _:_ -> ok
end.

init_per_group(admin_cets_http, Config) ->
Config1 = graphql_helper:init_admin_handler(Config),
skip_if_cets_not_configured(Config1);
Expand Down
17 changes: 9 additions & 8 deletions big_tests/tests/muc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ end_per_suite(Config) ->
escalus:end_per_suite(Config).

init_per_group(room_registration_race_condition, Config) ->
%% We init meck once per group, because recompiling module after
%% each testcase is slow.
meck_room(),
escalus_fresh:create_users(Config, [{alice, 1}]);

init_per_group(moderator, Config) ->
Expand Down Expand Up @@ -423,7 +426,7 @@ handle_http_auth(Req) ->
cowboy_req:reply(200, Headers, Resp, Req).

end_per_group(room_registration_race_condition, Config) ->
rpc(mim(), meck, unload, []),
unload_meck(),
escalus:delete_users(Config, escalus:get_users([bob, alice]));

end_per_group(admin_membersonly, Config) ->
Expand Down Expand Up @@ -460,16 +463,13 @@ end_per_group(_GroupName, Config) ->
escalus:delete_users(Config, escalus:get_users([alice, bob, kate])).

init_per_testcase(CaseName = create_already_registered_room, Config) ->
meck_room(),
meck_room_start(),
escalus:init_per_testcase(CaseName, Config);
init_per_testcase(CaseName = check_presence_route_to_offline_room, Config) ->
meck_room(),
meck_room_start(),
meck_room_route(),
escalus:init_per_testcase(CaseName, Config);
init_per_testcase(CaseName = check_message_route_to_offline_room, Config) ->
meck_room(),
meck_room_start(),
meck_room_route(),
escalus:init_per_testcase(CaseName, Config);
Expand Down Expand Up @@ -532,9 +532,13 @@ setup_mam(Backend) ->
muc => #{host => HostPattern}})}]).

meck_room() ->
RPCSpec = (mim())#{timeout => timer:seconds(10)}, % it takes long to compile this module
RPCSpec = (mim())#{timeout => timer:seconds(120)}, % it takes long to compile this module
ok = rpc(RPCSpec, meck, new, [mod_muc_room, [no_link, passthrough]]).

unload_meck() ->
RPCSpec = (mim())#{timeout => timer:seconds(120)},
rpc(RPCSpec, meck, unload, []).

%% Meck will register a fake room right before a 'real' room is started
meck_room_start() ->
rpc(mim(), meck, expect, [mod_muc_room, init, fun ?MODULE:meck_init/1]).
Expand All @@ -552,13 +556,10 @@ meck_room_route() ->
end]).

end_per_testcase(CaseName = create_already_registered_room, Config) ->
rpc(mim(), meck, unload, []),
escalus:end_per_testcase(CaseName, Config);
end_per_testcase(CaseName = check_presence_route_to_offline_room, Config) ->
rpc(mim(), meck, unload, []),
escalus:end_per_testcase(CaseName, Config);
end_per_testcase(CaseName = check_message_route_to_offline_room, Config) ->
rpc(mim(), meck, unload, []),
escalus:end_per_testcase(CaseName, Config);
end_per_testcase(CaseName = send_non_anonymous_history, Config) ->
destroy_room(Config),
Expand Down
4 changes: 4 additions & 0 deletions test/common/distributed_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ mim3() ->
fed() ->
rpc_spec(fed).

-spec reg() -> rpc_spec().
reg() ->
rpc_spec(reg).

rpc_spec(NodeKey) ->
#{node => get_or_fail({hosts, NodeKey, node})}.

Expand Down