Skip to content

Commit

Permalink
Merge pull request #4212 from esl/fully-disable-mnesia-in-tests
Browse files Browse the repository at this point in the history
Fully disable mnesia in tests
  • Loading branch information
NelsonVides authored Jan 16, 2024
2 parents e8087b4 + abe73bb commit 61830ee
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
37 changes: 27 additions & 10 deletions big_tests/tests/auth_methods_for_c2s_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ end_per_suite(Config) ->
escalus:end_per_suite(Config).

init_per_group(metrics, Config) ->
Config;
set_auth_mod(Config);
init_per_group(_, Config0) ->
Config1 = ejabberd_node_utils:init(Config0),
ejabberd_node_utils:backup_config_file(Config1),
modify_config_and_restart(Config1),
escalus_cleaner:start(Config1).
Config2 = modify_config_and_restart(Config1),
escalus_cleaner:start(Config2).

end_per_group(metrics, _Config) ->
escalus_fresh:clean();
Expand All @@ -49,20 +49,36 @@ end_per_group(_, Config) ->

init_per_testcase(TC, Config) ->
Spec = escalus_fresh:freshen_spec(Config, alice),
Clean = register_internal_user(Spec),
Clean = register_user(Config, Spec),
[{clean_fn, Clean}, {spec, Spec}|escalus:init_per_testcase(TC, Config)].

end_per_testcase(TC, Config) ->
Clean = proplists:get_value(clean_fn, Config),
Clean(),
escalus:end_per_testcase(TC, Config).

set_auth_mod(Config) ->
Mod = case mongoose_helper:is_rdbms_enabled(domain_helper:host_type()) of
true ->
ejabberd_auth_rdbms;
false ->
ejabberd_auth_internal
end,
[{auth_mod, Mod} | Config].

modify_config_and_restart(Config) ->
NewConfigValues = [{auth_method, "internal]\n [auth.dummy"},
{Method, Mod} = case mongoose_helper:is_rdbms_enabled(domain_helper:host_type()) of
true ->
{"rdbms", ejabberd_auth_rdbms};
false ->
{"internal", ejabberd_auth_internal}
end,
NewConfigValues = [{auth_method, Method ++ "]\n [auth.dummy"},
{auth_method_opts, false},
{allowed_auth_methods, "\"internal\""}],
{allowed_auth_methods, "\"" ++ Method ++ "\""}],
ejabberd_node_utils:modify_config_file(NewConfigValues, Config),
ejabberd_node_utils:restart_application(mongooseim).
ejabberd_node_utils:restart_application(mongooseim),
[{auth_mod, Mod} | Config].

can_login_with_allowed_method(Config) ->
Spec = proplists:get_value(spec, Config),
Expand Down Expand Up @@ -94,13 +110,14 @@ metrics_incremented_on_user_connect(ConfigIn) ->
%% Helpers
%% If dummy backend is enabled, it is not possible to create new users
%% (we check if an user does exist before registering the user).
register_internal_user(Spec) ->
register_user(Config, Spec) ->
Mod = proplists:get_value(auth_mod, Config),
#{username := User, server := Server,
password := Password} = maps:from_list(Spec),
LUser = jid:nodeprep(User),
LServer = escalus_utils:jid_to_lower(Server),
HostType = domain_helper:host_type(),
rpc(mim(), ejabberd_auth_internal, try_register,
ok = rpc(mim(), Mod, try_register,
[HostType, LUser, LServer, Password]),
fun() -> rpc(mim(), ejabberd_auth_internal, remove_user,
fun() -> rpc(mim(), Mod, remove_user,
[HostType, LUser, LServer]) end.
8 changes: 6 additions & 2 deletions big_tests/tests/mod_global_distrib_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@ init_per_suite(Config) ->
case {rpc(europe_node1, mongoose_wpool, get_worker, [redis, global, global_distrib]),
rpc(asia_node, mongoose_wpool, get_worker, [redis, global, global_distrib])} of
{{ok, _}, {ok, _}} ->
ok = rpc(europe_node2, mongoose_cluster, join, [ct:get_config(europe_node1)]),

case ct_helper:get_internal_database() of
mnesia ->
ok = rpc(europe_node2, mongoose_cluster, join, [ct:get_config(europe_node1)]);
_ ->
ok
end,
enable_logging(),
escalus:init_per_suite([{add_advertised_endpoints, []}, {extra_config, #{}} | Config]);
Result ->
Expand Down
3 changes: 1 addition & 2 deletions src/mongoose_internal_databases.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ init() ->
%% Ensure mnesia is stopped when applying the test presets from the big tests.
%% So, we accidentually do not test with mnesia enabled, when starting the
%% test cases from the clean test build.
%% TODO Stopping here would break a lot of tests, stop here once tests are fixed.
% mnesia:stop(),
mnesia:stop(),
ok
end.

Expand Down

0 comments on commit 61830ee

Please sign in to comment.