Skip to content

Commit

Permalink
Merge pull request #3398 from esl/do-not-set-module-opts-big-tests
Browse files Browse the repository at this point in the history
Do not use gen_mod:set_module_opt(s) in big tests
  • Loading branch information
chrzaszcz authored Nov 17, 2021
2 parents 9c57dde + baf08cd commit d7b9ec5
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 62 deletions.
3 changes: 0 additions & 3 deletions big_tests/tests/domain_removal_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ end_per_testcase(muc_removal, Config) ->
mongoose_helper:ensure_muc_clean(),
muc_helper:unload_muc(),
escalus:end_per_testcase(muc_removal, Config);
end_per_testcase(roster_removal, Config) ->
roster_helper:restore_versioning(Config),
escalus:end_per_testcase(roster_removal, Config);
end_per_testcase(TestCase, Config) ->
escalus:end_per_testcase(TestCase, Config).

Expand Down
115 changes: 73 additions & 42 deletions big_tests/tests/mam_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,9 @@ init_per_group(muc06, Config) ->
[{props, mam06_props()}, {with_rsm, true}|Config];

init_per_group(muc_configurable_archiveid, Config) ->
[backup_module_opts(mod_mam_muc) | Config];
dynamic_modules:save_modules(host_type(), Config);
init_per_group(configurable_archiveid, Config) ->
[backup_module_opts(mod_mam) | Config];
dynamic_modules:save_modules(host_type(), Config);

init_per_group(muc_rsm_all, Config) ->
Config1 = escalus_fresh:create_users(Config, [{N, 1} || N <- user_names()]),
Expand All @@ -609,21 +609,15 @@ init_per_group(Group, ConfigIn) ->
Config0 ->
ct:pal("Init per group ~p; configuration ~p; basic group ~p",
[Group, C, B]),
Config1 = do_init_per_group(C, Config0),
Config01 = dynamic_modules:save_modules(host_type(), Config0),
Config1 = do_init_per_group(C, Config01),
[{basic_group, B}, {configuration, C} | init_state(C, B, Config1)]
catch Class:Reason:Stacktrace ->
ct:pal("Failed to start configuration=~p basic_group=~p",
[C, B]),
erlang:raise(Class, Reason, Stacktrace)
end.

backup_module_opts(Module) ->
{{params_backup, Module}, rpc_apply(gen_mod, get_module_opts, [host_type(), Module])}.

restore_module_opts(Module, Config) ->
ParamsB = proplists:get_value({params_backup, Module}, Config),
rpc_apply(gen_mod, set_module_opts, [host_type(), Module, ParamsB]).

do_init_per_group(C, ConfigIn) ->
Config0 = create_users(ConfigIn),
case C of
Expand All @@ -643,17 +637,18 @@ end_per_group(G, Config) when G == rsm_all; G == nostore;
G == archived; G == mam_metrics ->
Config;
end_per_group(muc_configurable_archiveid, Config) ->
restore_module_opts(mod_mam_muc, Config),
dynamic_modules:restore_modules(host_type(), Config),
Config;
end_per_group(configurable_archiveid, Config) ->
restore_module_opts(mod_mam, Config),
dynamic_modules:restore_modules(host_type(), Config),
Config;
end_per_group(muc_rsm_all, Config) ->
destroy_room(Config);
end_per_group(Group, Config) ->
C = configuration(Group),
B = basic_group(Group),
Config1 = end_state(C, B, Config),
Config0 = dynamic_modules:restore_modules(Config),
Config1 = end_state(C, B, Config0),
Config2 = end_modules(C, B, Config1),
escalus_fresh:clean(),
delete_users(Config2).
Expand Down Expand Up @@ -916,9 +911,8 @@ init_per_testcase(C, Config) when C =:= retract_message;
skip_if_retraction_not_supported(Config, fun() -> escalus:init_per_testcase(C, Config) end);
init_per_testcase(C=retract_message_on_stanza_id, Config) ->
Init = fun() ->
OrigVal = rpc(mim(), gen_mod, get_module_opt, [host_type(), mod_mam, same_mam_id_for_peers, false]),
true = rpc(mim(), gen_mod, set_module_opt, [host_type(), mod_mam, same_mam_id_for_peers, true]),
escalus:init_per_testcase(C, [{same_mam_id_for_peers, OrigVal} | Config])
dynamic_modules:ensure_modules(host_type(), required_modules(C)),
escalus:init_per_testcase(C, Config)
end,
skip_if_retraction_not_supported(Config, Init);
init_per_testcase(C=offline_message, Config) ->
Expand Down Expand Up @@ -946,23 +940,23 @@ init_per_testcase(C=muc_archive_request, Config) ->
end,
escalus:init_per_testcase(C, start_alice_room(Config2));
init_per_testcase(C=muc_no_elements, Config) ->
rpc_apply(gen_mod, set_module_opts, [host_type(), mod_mam_muc, [no_stanzaid_element]]),
dynamic_modules:ensure_modules(host_type(), required_modules(C)),
Config1 = escalus_fresh:create_users(Config, [{alice, 1}, {bob, 1}]),
escalus:init_per_testcase(C, start_alice_room(Config1));
init_per_testcase(C=muc_only_stanzaid, Config) ->
rpc_apply(gen_mod, set_module_opts, [host_type(), mod_mam_muc, []]),
dynamic_modules:ensure_modules(host_type(), required_modules(C)),
Config1 = escalus_fresh:create_users(Config, [{alice, 1}, {bob, 1}]),
escalus:init_per_testcase(C, start_alice_room(Config1));
init_per_testcase(C=no_elements, Config) ->
rpc_apply(gen_mod, set_module_opts, [host_type(), mod_mam, [no_stanzaid_element]]),
dynamic_modules:ensure_modules(host_type(), required_modules(C)),
Config1 = escalus_fresh:create_users(Config, [{alice, 1}, {bob, 1}]),
escalus:init_per_testcase(C, start_alice_room(Config1));
init_per_testcase(C=only_stanzaid, Config) ->
rpc_apply(gen_mod, set_module_opts, [host_type(), mod_mam, []]),
dynamic_modules:ensure_modules(host_type(), required_modules(C)),
Config1 = escalus_fresh:create_users(Config, [{alice, 1}, {bob, 1}]),
escalus:init_per_testcase(C, start_alice_room(Config1));
init_per_testcase(C=same_stanza_id, Config) ->
rpc_apply(gen_mod, set_module_opts, [host_type(), mod_mam, [same_mam_id_for_peers]]),
dynamic_modules:ensure_modules(host_type(), required_modules(C)),
Config1 = escalus_fresh:create_users(Config, [{alice, 1}, {bob, 1}]),
escalus:init_per_testcase(C, start_alice_room(Config1));
init_per_testcase(C=muc_message_with_stanzaid, Config) ->
Expand Down Expand Up @@ -1022,18 +1016,15 @@ init_per_testcase(C=muc_text_search_request, Config) ->

skip_if_cassandra(Config, Init);
init_per_testcase(C = muc_light_stored_in_pm_if_allowed_to, Config) ->
OrigVal = rpc(mim(), gen_mod, get_module_opt, [host_type(), mod_mam, archive_groupchats, false]),
true = rpc(mim(), gen_mod, set_module_opt, [host_type(), mod_mam, archive_groupchats, true]),
dynamic_modules:ensure_modules(host_type(), required_modules(C, Config)),
clean_archives(Config),
escalus:init_per_testcase(C, [{archive_groupchats_backup, OrigVal} | Config]);
init_per_testcase(C = muc_light_chat_markers_are_archived_if_enabled, ConfigIn) ->
Config1 = [backup_module_opts(mod_mam_muc) | ConfigIn],
rpc_apply(gen_mod, set_module_opt, [host_type(), mod_mam_muc, archive_chat_markers, true]),
escalus:init_per_testcase(C, Config1);
init_per_testcase(C = muc_light_chat_markers_are_not_archived_if_disabled, ConfigIn) ->
Config1 = [backup_module_opts(mod_mam_muc) | ConfigIn],
rpc_apply(gen_mod, set_module_opt, [host_type(), mod_mam_muc, archive_chat_markers, false]),
escalus:init_per_testcase(C, Config1);
escalus:init_per_testcase(C, Config);
init_per_testcase(C, Config) when C =:= muc_light_simple;
C =:= muc_light_shouldnt_modify_pm_archive;
C =:= muc_light_chat_markers_are_archived_if_enabled;
C =:= muc_light_chat_markers_are_not_archived_if_disabled->
dynamic_modules:ensure_modules(host_type(), required_modules(C, Config)),
escalus:init_per_testcase(C, Config);
init_per_testcase(C=archive_chat_markers, Config) ->
Config1 = escalus_fresh:create_users(Config, [{alice, 1}, {bob, 1}]),
escalus:init_per_testcase(C, Config1);
Expand Down Expand Up @@ -1114,23 +1105,63 @@ end_per_testcase(C=muc_no_elements, Config) ->
end_per_testcase(C=muc_only_stanzaid, Config) ->
destroy_room(Config),
escalus:end_per_testcase(C, Config);
end_per_testcase(C = muc_light_stored_in_pm_if_allowed_to, Config0) ->
{value, {_, OrigVal}, Config1} = lists:keytake(archive_groupchats_backup, 1, Config0),
true = rpc(mim(), gen_mod, set_module_opt, [host_type(), mod_mam, archive_groupchats, OrigVal]),
escalus:end_per_testcase(C, Config1);
end_per_testcase(C = retract_message_on_stanza_id, Config0) ->
{value, {_, OrigVal}, Config1} = lists:keytake(same_mam_id_for_peers, 1, Config0),
true = rpc(mim(), gen_mod, set_module_opt, [host_type(), mod_mam, same_mam_id_for_peers, OrigVal]),
escalus:end_per_testcase(C, Config1);
end_per_testcase(C = muc_light_stored_in_pm_if_allowed_to, Config) ->
escalus:end_per_testcase(C, Config);
end_per_testcase(C = retract_message_on_stanza_id, Config) ->
escalus:end_per_testcase(C, Config);
end_per_testcase(C = muc_light_chat_markers_are_archived_if_enabled, Config) ->
restore_module_opts(mod_mam_muc, Config),
escalus:end_per_testcase(C, Config);
end_per_testcase(C = muc_light_chat_markers_are_not_archived_if_disabled, Config) ->
restore_module_opts(mod_mam_muc, Config),
escalus:end_per_testcase(C, Config);
end_per_testcase(C = no_elements, Config) ->
escalus:end_per_testcase(C, Config);
end_per_testcase(C = only_stanzaid, Config) ->
escalus:end_per_testcase(C, Config);
end_per_testcase(C = same_stanza_id, Config) ->
escalus:end_per_testcase(C, Config);
end_per_testcase(CaseName, Config) ->
escalus:end_per_testcase(CaseName, Config).

%% Module configuration per testcase

required_modules(Case) ->
required_modules(Case, []).

% muc_light basic group
required_modules(muc_light_simple, Config) ->
[{mod_mam, [{archive_groupchats, false}]},
{mod_mam_muc, dynamic_modules:get_saved_config(host_type(), mod_mam_muc, Config)}];
required_modules(muc_light_shouldnt_modify_pm_archive, Config) ->
[{mod_mam, [{archive_groupchats, false}]},
{mod_mam_muc, dynamic_modules:get_saved_config(host_type(), mod_mam_muc, Config)}];
required_modules(muc_light_stored_in_pm_if_allowed_to, Config) ->
[{mod_mam, [{archive_groupchats, true}]},
{mod_mam_muc, dynamic_modules:get_saved_config(host_type(), mod_mam_muc, Config)}];
required_modules(muc_light_chat_markers_are_archived_if_enabled, Config) ->
Opts = dynamic_modules:get_saved_config(host_type(), mod_mam_muc, Config),
[{mod_mam, [{archive_groupchats, false}]},
{mod_mam_muc, [{archive_chat_markers, true} | Opts]}];
required_modules(muc_light_chat_markers_are_not_archived_if_disabled, Config) ->
Opts = dynamic_modules:get_saved_config(host_type(), mod_mam_muc, Config),
[{mod_mam, [{archive_groupchats, false}]},
{mod_mam_muc, [{archive_chat_markers, false} | Opts]}];
% muc_configurable_archiveid basic group
required_modules(muc_no_elements, _Config) ->
[{mod_mam_muc, [no_stanzaid_element]}];
required_modules(muc_only_stanzaid, _Config) ->
[{mod_mam_muc, []}];
% configurable_archiveid basic group
required_modules(no_elements, _Config) ->
[{mod_mam, [no_stanzaid_element]}];
required_modules(only_stanzaid, _Config) ->
[{mod_mam, []}];
required_modules(same_stanza_id, _Config) ->
[{mod_mam, [same_mam_id_for_peers]}];
required_modules(retract_message_on_stanza_id, _Config) ->
[{mod_mam, [{same_mam_id_for_peers, true}]}];
required_modules(_, _) ->
[].

init_module(Host, Mod, Args) ->
lists:member(Mod, mam_modules())
orelse
Expand Down
7 changes: 6 additions & 1 deletion big_tests/tests/presence_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@ end_per_suite(Config) ->
escalus_fresh:clean(),
escalus:end_per_suite(Config).

init_per_group(roster_versioning, Config) ->
Config0 = dynamic_modules:save_modules(host_type(), Config),
escalus:create_users(Config0, escalus:get_users([alice, bob]));
init_per_group(_GroupName, Config) ->
escalus:create_users(Config, escalus:get_users([alice, bob])).

end_per_group(roster_versioning, Config) ->
dynamic_modules:restore_modules(Config),
escalus:delete_users(Config, escalus:get_users([alice, bob]));
end_per_group(_GroupName, Config) ->
escalus:delete_users(Config, escalus:get_users([alice, bob])).

Expand All @@ -103,7 +109,6 @@ end_per_testcase(unsubscribe, Config) ->
end_rosters_remove(Config);
end_per_testcase(VersionCases, Config)
when VersionCases =:= versioning; VersionCases =:= versioning_no_store ->
restore_versioning(Config),
end_rosters_remove(Config);
end_per_testcase(CaseName, Config) ->
escalus:end_per_testcase(CaseName, Config).
Expand Down
21 changes: 5 additions & 16 deletions big_tests/tests/roster_helper.erl
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
-module(roster_helper).
-export([set_versioning/3, restore_versioning/1]).
-export([set_versioning/3]).

-import(distributed_helper, [mim/0, rpc/4]).
-import(domain_helper, [host_type/0]).

-spec set_versioning(boolean(), boolean(), escalus_config:config()) -> escalus_config:config().
set_versioning(Versioning, VersionStore, Config) ->
RosterVersioning = rpc(mim(), gen_mod, get_module_opt,
[host_type(), mod_roster, versioning, false]),
RosterVersionOnDb = rpc(mim(), gen_mod, get_module_opt,
[host_type(), mod_roster, store_current_id, false]),
rpc(mim(), gen_mod, set_module_opt, [host_type(), mod_roster, versioning, Versioning]),
rpc(mim(), gen_mod, set_module_opt, [host_type(), mod_roster, store_current_id, VersionStore]),
[{versioning, RosterVersioning},
{store_current_id, RosterVersionOnDb} | Config].

-spec restore_versioning(escalus_config:config()) -> escalus_config:config().
restore_versioning(Config) ->
RosterVersioning = proplists:get_value(versioning, Config),
RosterVersionOnDb = proplists:get_value(store_current_id, Config),
rpc(mim(), gen_mod, get_module_opt, [host_type(), mod_roster, versioning, RosterVersioning]),
rpc(mim(), gen_mod, get_module_opt, [host_type(), mod_roster, store_current_id, RosterVersionOnDb]).
Opts = dynamic_modules:get_saved_config(host_type(), mod_roster, Config),
dynamic_modules:ensure_modules(host_type(), [{mod_roster, [{versioning, Versioning},
{store_current_id, VersionStore} | Opts]}]),
Config.

0 comments on commit d7b9ec5

Please sign in to comment.