Skip to content

Commit

Permalink
Merge pull request #3416 from esl/tests/enable_db_modules_only_when_used
Browse files Browse the repository at this point in the history
Tests/enable db modules only when used
  • Loading branch information
arcusfelis authored Nov 25, 2021
2 parents f7e0f9d + 272c6fe commit bd34cea
Show file tree
Hide file tree
Showing 20 changed files with 128 additions and 58 deletions.
12 changes: 0 additions & 12 deletions big_tests/test.config
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,6 @@
connection.tls.cacertfile = \"priv/ssl/cacert.pem\"
connection.tls.server_name_indication = false"},
{service_domain_db, ""},
{mod_privacy, " backend = \"rdbms\"\n"},
{mod_private, " backend = \"rdbms\"\n"},
{mod_offline, " backend = \"rdbms\"\n"},
{mod_vcard, " backend = \"rdbms\"
host = \"vjud.@HOST@\"\n"},
{mod_roster, " backend = \"rdbms\"\n"}]},
Expand All @@ -274,9 +271,6 @@
connection.driver = \"odbc\"
connection.settings = \"DSN=mongoose-mssql;UID=sa;PWD=mongooseim_secret+ESL123\""},
{service_domain_db, ""},
{mod_privacy, " backend = \"rdbms\"\n"},
{mod_private, " backend = \"rdbms\"\n"},
{mod_offline, " backend = \"rdbms\"\n"},
{mod_vcard, " backend = \"rdbms\"
host = \"vjud.@HOST@\"\n"},
{mod_roster, " backend = \"rdbms\"\n"}]},
Expand All @@ -303,9 +297,6 @@
connection.tls.cacertfile = \"priv/ssl/cacert.pem\"
connection.tls.versions = [\"tlsv1.2\"]"},
{service_domain_db, ""},
{mod_privacy, " backend = \"rdbms\"\n"},
{mod_private, " backend = \"rdbms\"\n"},
{mod_offline, " backend = \"rdbms\"\n"},
{mod_vcard, " backend = \"rdbms\"
host = \"vjud.@HOST@\"\n"},
{mod_roster, " backend = \"rdbms\"\n"}]},
Expand Down Expand Up @@ -366,9 +357,6 @@
connection.tls.ciphers = \"AES256-SHA:DHE-RSA-AES128-SHA256\"
connection.tls.server_name_indication = false
connection.tls.cacertfile = \"priv/ssl/cacert.pem\""},
{mod_privacy, " backend = \"riak\"\n"},
{mod_private, " backend = \"riak\"\n"},
{mod_offline, " backend = \"riak\"\n"},
{mod_vcard, " backend = \"riak\"
host = \"vjud.@HOST@\"\n"},
{mod_roster, " backend = \"riak\"\n"}
Expand Down
13 changes: 10 additions & 3 deletions big_tests/tests/amp_big_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -979,11 +979,11 @@ is_module_loaded(Mod) ->
rpc(mim(), gen_mod, is_loaded, [host_type(), Mod]).

required_modules(basic) ->
mam_modules(off) ++ offline_modules(off);
mam_modules(off) ++ offline_modules(off) ++ privacy_modules(on);
required_modules(mam) ->
mam_modules(on) ++ offline_modules(off);
mam_modules(on) ++ offline_modules(off) ++ privacy_modules(off);
required_modules(offline) ->
mam_modules(off) ++ offline_modules(on);
mam_modules(off) ++ offline_modules(on) ++ privacy_modules(on);
required_modules(_) ->
[].

Expand All @@ -1000,3 +1000,10 @@ offline_modules(on) ->
offline_modules(off) ->
[{mod_offline, stopped},
{mod_offline_stub, []}].

privacy_modules(on) ->
[{mod_privacy, []},
{mod_blocking, []}];
privacy_modules(off) ->
[{mod_privacy, stopped},
{mod_blocking, stopped}].
12 changes: 8 additions & 4 deletions big_tests/tests/gdpr_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ init_per_suite(Config) ->

end_per_suite(Config) ->
delete_files(),
dynamic_modules:restore_modules(host_type(), Config),
escalus_fresh:clean(),
dynamic_modules:restore_modules(host_type(), Config),
escalus:end_per_suite(Config).

init_per_group(GN, Config) when GN =:= remove_personal_data_mam_rdbms;
Expand All @@ -214,6 +214,9 @@ init_per_group(retrieve_personal_data_inbox = GN, Config) ->
init_inbox(GN, Config, muclight);
init_per_group(remove_personal_data_inbox = GN, Config) ->
init_inbox(GN, Config, muclight);
init_per_group(retrieve_personal_data_private_xml, Config) ->
private_started(),
Config;
init_per_group(_GN, Config) ->
Config.

Expand All @@ -237,7 +240,8 @@ init_per_testcase(retrieve_logs = CN, Config) ->
false -> {skip, not_running_in_distributed};
_ -> escalus:init_per_testcase(CN, Config)
end;
init_per_testcase(remove_offline = CN, Config) ->
init_per_testcase(CN, Config) when CN =:= remove_offline;
CN =:= retrieve_offline ->
offline_started(),
escalus:init_per_testcase(CN, Config);
init_per_testcase(CN, Config) when
Expand Down Expand Up @@ -311,15 +315,15 @@ init_per_testcase(CN, Config) ->
end_per_testcase(CN, Config) when CN =:= retrieve_mam_muc_light;
CN =:= retrieve_mam_pm_and_muc_light_interfere;
CN =:= retrieve_mam_pm_and_muc_light_dont_interfere ->
muc_light_helper:clear_db(),
muc_light_helper:clear_db(host_type()),
escalus:end_per_testcase(CN, Config);
%% mod_inbox
end_per_testcase(CN, Config) when
CN =:= remove_inbox;
CN =:= retrieve_inbox;
CN =:= remove_inbox_muclight;
CN =:= retrieve_inbox_muclight ->
muc_light_helper:clear_db(),
muc_light_helper:clear_db(host_type()),
escalus:end_per_testcase(CN, Config);
end_per_testcase(CN, Config) when CN =:= retrieve_inbox_muc;
CN =:= remove_inbox_muc ->
Expand Down
15 changes: 7 additions & 8 deletions big_tests/tests/inbox_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,10 @@ suite() ->
%% Init & teardown
%%--------------------------------------------------------------------

init_per_suite(Config) ->
init_per_suite(Config0) ->
Config1 = dynamic_modules:save_modules(domain_helper:host_type(), Config0),
ok = dynamic_modules:ensure_modules(
domain_helper:host_type(mim), inbox_modules()),
domain_helper:host_type(), inbox_modules()),
ok = dynamic_modules:ensure_modules(
ct:get_config({hosts, mim, secondary_host_type}),
[{mod_inbox,
Expand All @@ -207,18 +208,16 @@ init_per_suite(Config) ->
{groupchat, [muclight]},
{markers, [displayed]}]}]),
InboxOptions = inbox_opts(),
Config1 = escalus:init_per_suite(Config),
[{inbox_opts, InboxOptions} | Config1].
escalus:init_per_suite([{inbox_opts, InboxOptions} | Config1]).

end_per_suite(Config) ->
dynamic_modules:stop(
domain_helper:host_type(mim), mod_inbox),
dynamic_modules:stop(
ct:get_config({hosts, mim, secondary_host_type}), mod_inbox),
escalus_fresh:clean(),
dynamic_modules:stop(ct:get_config({hosts, mim, secondary_host_type}), mod_inbox),
dynamic_modules:restore_modules(domain_helper:host_type(), Config),
escalus:end_per_suite(Config).

init_per_group(one_to_one, Config) ->
dynamic_modules:ensure_modules(domain_helper:host_type(), [{mod_offline, []}]),
inbox_helper:reload_inbox_option(Config, groupchat, []);
init_per_group(muclight, Config) ->
ok = dynamic_modules:ensure_modules(domain_helper:host_type(mim), muclight_modules()),
Expand Down
9 changes: 1 addition & 8 deletions big_tests/tests/last_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ suite() ->
init_per_suite(Config0) ->
HostType = domain_helper:host_type(),
Config1 = dynamic_modules:save_modules(HostType, Config0),
Backend = get_configured_backend(HostType),
Backend = mongoose_helper:get_backend_mnesia_rdbms_riak(HostType),
dynamic_modules:ensure_modules(HostType, required_modules(Backend)),
escalus:init_per_suite([{backend, Backend} | Config1]).

Expand Down Expand Up @@ -162,12 +162,5 @@ get_last_activity(Stanza) ->
get_last_status(Stanza) ->
exml_query:path(Stanza, [{element, <<"query">>}, cdata]).

get_configured_backend(HostType) ->
case {mongoose_helper:is_rdbms_enabled(HostType), mam_helper:is_riak_enabled(HostType)} of
{false, false} -> mnesia;
{true, false} -> rdbms;
{false, true} -> riak
end.

required_modules(Backend) ->
[{mod_last, [{backend, Backend}]}].
13 changes: 9 additions & 4 deletions big_tests/tests/mod_blocking_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,18 @@ suite() ->
%% Init & teardown
%%--------------------------------------------------------------------

init_per_suite(Config) ->
escalus:init_per_suite(Config).
%% [{escalus_no_stanzas_after_story, true} |
%% escalus:init_per_suite(Config)].
init_per_suite(Config0) ->
HostType = domain_helper:host_type(),
Config1 = dynamic_modules:save_modules(HostType, Config0),
Backend = mongoose_helper:get_backend_mnesia_rdbms_riak(HostType),
ModConfig = mongoose_helper:backend_for_module(mod_blocking, Backend),
dynamic_modules:ensure_modules(HostType, ModConfig),
[{backend, Backend} |
escalus:init_per_suite(Config1)].

end_per_suite(Config) ->
escalus_fresh:clean(),
dynamic_modules:restore_modules(Config),
escalus:end_per_suite(Config).

init_per_group(_GroupName, Config) ->
Expand Down
10 changes: 6 additions & 4 deletions big_tests/tests/mod_event_pusher_http_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

-import(push_helper, [http_notifications_port/0, http_notifications_host/0]).

-import(domain_helper, [domain/0]).
-import(domain_helper, [host_type/0]).

%%%===================================================================
%%% Suite configuration
Expand Down Expand Up @@ -63,7 +63,7 @@ init_per_group(with_prefix, Config) ->
set_modules(Config, [{path, "/prefix"}]).

end_per_group(_GroupName, Config) ->
dynamic_modules:restore_modules(domain(), Config),
dynamic_modules:restore_modules(host_type(), Config),
ok.

init_per_testcase(CaseName, Config) ->
Expand Down Expand Up @@ -177,12 +177,14 @@ stop_pool() ->
ejabberd_node_utils:call_fun(mongoose_wpool, stop, [http, global, http_pool]).

set_modules(Config0, Opts) ->
Config = dynamic_modules:save_modules(domain(), Config0),
Config = dynamic_modules:save_modules(host_type(), Config0),
Backend = mongoose_helper:get_backend_mnesia_rdbms_riak(host_type()),
ModOffline = mongoose_helper:backend_for_module(mod_offline, Backend),
ModOpts = [{backends,
[{http,
[{worker_timeout, 500},
{host, http_notifications_host()}] ++ Opts}]}],
dynamic_modules:ensure_modules(domain(), [{mod_event_pusher, ModOpts}]),
dynamic_modules:ensure_modules(host_type(), [{mod_event_pusher, ModOpts} | ModOffline]),
Config.

start_http_listener(simple_message, Prefix) ->
Expand Down
12 changes: 12 additions & 0 deletions big_tests/tests/mongoose_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
%% API

-export([is_rdbms_enabled/1,
get_backend_mnesia_rdbms_riak/1,
backend_for_module/2,
mnesia_or_rdbms_backend/0,
get_backend_name/2]).

Expand Down Expand Up @@ -64,6 +66,16 @@ mnesia_or_rdbms_backend() ->
false -> mnesia
end.

get_backend_mnesia_rdbms_riak(HostType) ->
case {is_rdbms_enabled(HostType), mam_helper:is_riak_enabled(HostType)} of
{false, false} -> mnesia;
{true, false} -> rdbms;
{false, true} -> riak
end.

backend_for_module(Module, Backend) ->
[{Module, [{backend, Backend}]}].

-spec auth_modules() -> [atom()].
auth_modules() ->
Hosts = rpc(mim(), mongoose_config, get_opt, [hosts]),
Expand Down
12 changes: 12 additions & 0 deletions big_tests/tests/mongooseimctl_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ end_per_suite(Config) ->
dynamic_modules:stop(domain_helper:secondary_host_type(), mod_last),
escalus:end_per_suite(Config1).

init_per_group(basic, Config) ->
dynamic_modules:ensure_modules(domain_helper:host_type(), [{mod_offline, []}]),
Config;
init_per_group(private, Config) ->
dynamic_modules:ensure_modules(domain_helper:host_type(), [{mod_private, []}]),
Config;
init_per_group(vcard, Config) ->
case rpc(mim(), gen_mod, get_module_opt, [host_type(), mod_vcard, backend, mnesia]) of
ldap ->
Expand All @@ -238,6 +244,12 @@ init_per_group(upload_with_acl, Config) ->
init_per_group(_GroupName, Config) ->
Config.

end_per_group(basic, Config) ->
dynamic_modules:stop(domain_helper:host_type(), mod_offline),
Config;
end_per_group(private, Config) ->
dynamic_modules:stop(domain_helper:host_type(), mod_private),
Config;
end_per_group(Rosters, Config) when (Rosters == roster) or (Rosters == roster_advanced) ->
TemplatePath = escalus_config:get_config(roster_template, Config),
RegUsers = [atom_to_list(U) || {U, _} <- escalus_config:get_config(escalus_users, Config)],
Expand Down
15 changes: 13 additions & 2 deletions big_tests/tests/offline_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,19 @@ suite() ->
%%% Init & teardown
%%%===================================================================

init_per_suite(C) -> escalus:init_per_suite(C).
end_per_suite(C) -> escalus_fresh:clean(), escalus:end_per_suite(C).
init_per_suite(Config0) ->
HostType = domain_helper:host_type(),
Config1 = dynamic_modules:save_modules(HostType, Config0),
Backend = mongoose_helper:get_backend_mnesia_rdbms_riak(HostType),
ModConfig = mongoose_helper:backend_for_module(mod_offline, Backend),
dynamic_modules:ensure_modules(HostType, ModConfig),
[{backend, Backend} |
escalus:init_per_suite(Config1)].

end_per_suite(Config) ->
escalus_fresh:clean(),
dynamic_modules:restore_modules(Config),
escalus:end_per_suite(Config).

init_per_group(with_groupchat, C) ->
Config = dynamic_modules:save_modules(host_type(), C),
Expand Down
13 changes: 10 additions & 3 deletions big_tests/tests/privacy_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,19 @@ suite() ->
%% Init & teardown
%%--------------------------------------------------------------------

init_per_suite(Config) ->
[{escalus_no_stanzas_after_story, true} |
escalus:init_per_suite(Config)].
init_per_suite(Config0) ->
HostType = domain_helper:host_type(),
Config1 = dynamic_modules:save_modules(HostType, Config0),
Backend = mongoose_helper:get_backend_mnesia_rdbms_riak(HostType),
ModConfig = mongoose_helper:backend_for_module(mod_privacy, Backend),
dynamic_modules:ensure_modules(HostType, ModConfig),
[{escalus_no_stanzas_after_story, true},
{backend, Backend} |
escalus:init_per_suite(Config1)].

end_per_suite(Config) ->
escalus_fresh:clean(),
dynamic_modules:restore_modules(Config),
escalus:end_per_suite(Config).

init_per_group(_GroupName, Config) ->
Expand Down
12 changes: 10 additions & 2 deletions big_tests/tests/private_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ negative_test_cases() ->
suite() ->
escalus:suite().

init_per_suite(Config) ->
escalus:init_per_suite(Config).
init_per_suite(Config0) ->
HostType = domain_helper:host_type(),
Config1 = dynamic_modules:save_modules(HostType, Config0),
Backend = mongoose_helper:get_backend_mnesia_rdbms_riak(HostType),
ModConfig = mongoose_helper:backend_for_module(mod_private, Backend),
dynamic_modules:ensure_modules(HostType, ModConfig),
escalus:init_per_suite([{backend, Backend} | Config1]).

end_per_suite(Config) ->
dynamic_modules:restore_modules(Config),
escalus:end_per_suite(Config).

init_per_group(_GroupName, Config) ->
Expand Down Expand Up @@ -167,3 +173,5 @@ check_body_rec(Element, [Name | Names]) ->
Name = Child#xmlel.name,
check_body_rec(Child, Names).

required_modules(Backend) ->
[{mod_private, [{backend, Backend}]}].
4 changes: 3 additions & 1 deletion big_tests/tests/push_integration_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,9 @@ mongoose_push_api_for_group(_) ->
"v3".

required_modules_for_group(pm_notifications_with_inbox, API, PubSubHost) ->
[{mod_inbox, inbox_opts()} | required_modules(API, PubSubHost)];
[{mod_inbox, inbox_opts()},
{mod_offline, []} |
required_modules(API, PubSubHost)];
required_modules_for_group(groupchat_notifications_with_inbox, API, PubSubHost)->
[{mod_inbox, inbox_opts()}, {mod_muc_light, muc_light_opts()}
| required_modules(API, PubSubHost)];
Expand Down
4 changes: 2 additions & 2 deletions big_tests/tests/sm_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ init_per_suite(Config) ->
escalus:init_per_suite(NewConfigWithSM).

end_per_suite(Config) ->
dynamic_modules:restore_modules(Config),
escalus_fresh:clean(),
dynamic_modules:restore_modules(Config),
escalus:end_per_suite(Config).

init_per_group(Group, Config) when Group =:= unacknowledged_message_hook;
Expand Down Expand Up @@ -178,7 +178,7 @@ required_modules(Scope, Name) ->
stopped -> stopped;
ExtraOpts -> common_sm_opts() ++ ExtraOpts
end,
[{mod_stream_management, SMConfig}].
[{mod_stream_management, SMConfig}, {mod_offline, []}].

required_sm_opts(group, parallel) ->
[{ack_freq, never}];
Expand Down
8 changes: 5 additions & 3 deletions big_tests/tests/xep_0352_csi_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ suite() ->
escalus:suite().

init_per_suite(Config) ->
dynamic_modules:start(host_type(), mod_csi, [{buffer_max, ?CSI_BUFFER_MAX}]),
[{escalus_user_db, {module, escalus_ejabberd}} | escalus:init_per_suite(Config)].
NewConfig = dynamic_modules:save_modules(host_type(), Config),
dynamic_modules:ensure_modules(
host_type(), [{mod_offline, []}, {mod_csi, [{buffer_max, ?CSI_BUFFER_MAX}]}]),
[{escalus_user_db, {module, escalus_ejabberd}} | escalus:init_per_suite(NewConfig)].

end_per_suite(Config) ->
dynamic_modules:stop(host_type(), mod_csi),
escalus_fresh:clean(),
dynamic_modules:restore_modules(Config),
escalus:end_per_suite(Config).

init_per_group(_, Config) ->
Expand Down
Loading

0 comments on commit bd34cea

Please sign in to comment.