Skip to content

Commit

Permalink
Add missing tests for CETS cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chrzaszcz committed Mar 26, 2024
1 parent 30e5e98 commit 5a009d1
Showing 1 changed file with 42 additions and 55 deletions.
97 changes: 42 additions & 55 deletions test/mongoose_cleanup_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,9 @@
-include_lib("common_test/include/ct.hrl").
-include("mongoose.hrl").

-export([all/0, groups/0,
init_per_suite/1, end_per_suite/1,
init_per_group/2, end_per_group/2,
init_per_testcase/2, end_per_testcase/2]).
-export([cleaner_runs_hook_on_nodedown/1,
cleaner_runs_hook_on_nodedown_for_host_type/1,
notify_self_hook/3,
notify_self_hook_for_host_type/3]).
-export([auth_anonymous/1,
last/1,
stream_management/1,
s2s/1,
bosh/1,
component/1,
component_from_other_node_remains/1,
muc_node_cleanup_for_host_type/1,
muc_room/1,
muc_room_from_other_node_remains/1
]).
-compile([export_all, nowarn_export_all]).

-define(HOST, <<"localhost">>).
-define(NS_CC_2, <<"urn:xmpp:carbons:2">>).

%% -----------------------------------------------------
%% CT callbacks
Expand All @@ -37,9 +18,6 @@ all() ->
cleaner_runs_hook_on_nodedown_for_host_type,
auth_anonymous,
last,
stream_management,
s2s,
bosh,
[{group, cets},
{group, mnesia}]
].
Expand All @@ -51,7 +29,7 @@ groups() ->
{muc, [], muc_cases()}].

backend_tests() ->
[{group, component}, {group, muc}].
[{group, component}, {group, muc}, bosh, stream_management, s2s].

component_cases() ->
[component, component_from_other_node_remains].
Expand Down Expand Up @@ -82,44 +60,35 @@ init_per_group(mnesia, Config) ->
[{backend, mnesia} | Config];
init_per_group(component, Config) ->
mongoose_config:set_opt(component_backend, ?config(backend, Config)),
[{needs_component, true} | Config];
init_per_group(s2s, Config) ->
mongoose_config:set_opt(s2s_backend, ?config(backend, Config)),
Config;
init_per_group(Group, Config) ->
mongoose_modules:replace_modules(?HOST, [], required_modules(Group, Config)),
start_modules(Group, Config),
Config.

end_per_group(cets, Config) ->
stop_cets_disco(Config);
end_per_group(mnesia, _Config) ->
ok;
end_per_group(Group, Config) ->
mongoose_modules:replace_modules(?HOST, maps:keys(required_modules(Group, Config)), #{}).
stop_modules(Group, Config).

init_per_testcase(TestCase, Config) ->
start_component(TestCase),
start_component_if_needed(?config(needs_component, Config)),
start_modules(TestCase, Config),
Config.

end_per_testcase(TestCase, _Config) ->
stop_component(TestCase).
end_per_testcase(TestCase, Config) ->
stop_modules(TestCase, Config),
stop_component_if_needed(?config(needs_component, Config)).

start_component(TestCase) ->
case needs_component(TestCase) of
true ->
mongoose_router:start(),
mongoose_component:start();
false ->
ok
end.

stop_component(TestCase) ->
case needs_component(TestCase) of
true ->
mongoose_component:stop();
false ->
ok
end.
start_modules(GroupOrCase, Config) ->
mongoose_modules:replace_modules(?HOST, [], required_modules(GroupOrCase, Config)).

needs_component(TestCase) ->
lists:member(TestCase, component_cases()).
stop_modules(GroupOrCase, Config) ->
mongoose_modules:replace_modules(?HOST, maps:keys(required_modules(GroupOrCase, Config)), #{}).

opts() ->
#{hosts => [?HOST],
Expand All @@ -133,6 +102,32 @@ meck_mods() ->
[exometer, mod_bosh_socket, cets_dist_blocker,
mongoose_bin, ejabberd_sm, ejabberd_local].

required_modules(muc, Config) ->
ExtraOpts = #{online_backend => ?config(backend, Config), backend => mnesia},
#{mod_muc => config_parser_helper:mod_config(mod_muc, ExtraOpts)};
required_modules(bosh, Config) ->
ExtraOpts = #{backend => ?config(backend, Config)},
#{mod_bosh => config_parser_helper:mod_config(mod_bosh, ExtraOpts)};
required_modules(stream_management, Config) ->
ExtraOpts = #{backend => ?config(backend, Config)},
#{mod_stream_management => config_parser_helper:mod_config(mod_stream_management, ExtraOpts)};
required_modules(_GroupOrCase, _Config) ->
#{}.

start_component_if_needed(true) ->
mongoose_router:start(),
mongoose_component:start();
start_component_if_needed(_) ->
ok.

stop_component_if_needed(true) ->
mongoose_component:stop();
stop_component_if_needed(_) ->
ok.

needs_component(TestCase) ->
lists:member(TestCase, component_cases()).

%% -----------------------------------------------------
%% Tests
%% -----------------------------------------------------
Expand Down Expand Up @@ -208,7 +203,6 @@ last(_Config) ->
stream_management(_Config) ->
HostType = ?HOST,
{U, S, R, _JID, SID} = get_fake_session(),
{started, ok} = start(HostType, mod_stream_management),
SMID = <<"123">>,
mod_stream_management:register_smid(HostType, SMID, SID),
{sid, SID} = mod_stream_management:get_sid(HostType, SMID),
Expand All @@ -225,7 +219,6 @@ s2s(_Config) ->
[] = ejabberd_s2s:get_s2s_out_pids(FromTo).

bosh(_Config) ->
{started, ok} = start(?HOST, mod_bosh),
SID = <<"sid">>,
Self = self(),
{error, _} = mod_bosh:get_session_socket(SID),
Expand Down Expand Up @@ -371,9 +364,3 @@ remote_pid_binary() ->

remote_pid() ->
binary_to_term(remote_pid_binary()).

required_modules(muc, Config) ->
ExtraOpts = #{online_backend => ?config(backend, Config), backend => mnesia},
#{mod_muc => config_parser_helper:mod_config(mod_muc, ExtraOpts)};
required_modules(_Group, _Config) ->
#{}.

0 comments on commit 5a009d1

Please sign in to comment.