Skip to content

Commit

Permalink
Merge pull request #4066 from esl/mu-cets-muc-legacy
Browse files Browse the repository at this point in the history
CETS backend for mod_muc
  • Loading branch information
chrzaszcz authored Aug 2, 2023
2 parents 5f98eeb + b3bede2 commit 3407849
Show file tree
Hide file tree
Showing 26 changed files with 502 additions and 152 deletions.
1 change: 1 addition & 0 deletions big_tests/test.config
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
{component_backend, "\"cets\""},
{s2s_backend, "\"cets\""},
{stream_management_backend, cets},
{muc_online_backend, cets},
{auth_method, "rdbms"},
{internal_databases, "[internal_databases.cets]
cluster_name = \"{{cluster_name}}\"
Expand Down
2 changes: 1 addition & 1 deletion big_tests/tests/domain_removal_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ is_internal_or_rdbms() ->
%%%===================================================================

init_per_testcase(muc_removal, Config) ->
muc_helper:load_muc(),
muc_helper:load_muc(Config),
mongoose_helper:ensure_muc_clean(),
escalus:init_per_testcase(muc_removal, Config);
init_per_testcase(roster_removal, ConfigIn) ->
Expand Down
4 changes: 2 additions & 2 deletions big_tests/tests/gdpr_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ all_mam_testcases() ->
init_per_suite(Config) ->
#{node := MimNode} = distributed_helper:mim(),
Config1 = [{{ejabberd_cwd, MimNode}, get_mim_cwd()} | dynamic_modules:save_modules(host_type(), Config)],
muc_helper:load_muc(),
muc_helper:load_muc(Config),
escalus:init_per_suite(Config1).

end_per_suite(Config) ->
Expand Down Expand Up @@ -243,7 +243,7 @@ init_per_testcase(CN, Config) when
Config1;
init_per_testcase(CN, Config) when CN =:= retrieve_inbox_muc;
CN =:= remove_inbox_muc ->
muc_helper:load_muc(),
muc_helper:load_muc(Config),
Config0 = init_inbox(CN, Config, muc),
Config0;

Expand Down
12 changes: 6 additions & 6 deletions big_tests/tests/graphql_muc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,20 @@ init_per_group(admin_cli, Config) ->
graphql_helper:init_admin_cli(Config);
init_per_group(domain_admin_muc, Config) ->
maybe_enable_mam(),
ensure_muc_started(),
ensure_muc_started(Config),
graphql_helper:init_domain_admin_handler(Config);
init_per_group(user, Config) ->
graphql_helper:init_user(Config);
init_per_group(Group, Config) when Group =:= admin_muc_configured;
Group =:= user_muc_configured ->
disable_mam(),
ensure_muc_started(),
ensure_muc_started(Config),
Config;
init_per_group(Group, Config) when Group =:= admin_muc_and_mam_configured;
Group =:= user_muc_and_mam_configured ->
case maybe_enable_mam() of
true ->
ensure_muc_started(),
ensure_muc_started(Config),
ensure_muc_light_started(Config);
false ->
{skip, "No MAM backend available"}
Expand All @@ -277,10 +277,10 @@ maybe_enable_mam() ->
true
end.

ensure_muc_started() ->
ensure_muc_started(Config) ->
SecondaryHostType = domain_helper:secondary_host_type(),
muc_helper:load_muc(),
muc_helper:load_muc(SecondaryHostType),
muc_helper:load_muc(Config),
muc_helper:load_muc(Config, SecondaryHostType),
mongoose_helper:ensure_muc_clean().

ensure_muc_stopped() ->
Expand Down
6 changes: 3 additions & 3 deletions big_tests/tests/graphql_muc_light_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ init_per_group(Group, Config) when Group =:= user_muc_light_with_mam;
Group =:= domain_admin_muc_light_with_mam ->
case maybe_enable_mam() of
true ->
ensure_muc_started(),
ensure_muc_started(Config),
ensure_muc_light_started(Config);
false ->
{skip, "No MAM backend available"}
Expand Down Expand Up @@ -281,8 +281,8 @@ ensure_muc_light_stopped(Config) ->
dynamic_modules:ensure_modules(SecondaryHostType, [{mod_muc_light, stopped}]),
[{muc_light_host, <<"NON_EXISTING">>} | Config].

ensure_muc_started() ->
muc_helper:load_muc(),
ensure_muc_started(Config) ->
muc_helper:load_muc(Config),
mongoose_helper:ensure_muc_clean().

ensure_muc_stopped() ->
Expand Down
2 changes: 1 addition & 1 deletion big_tests/tests/inbox_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ init_per_group(muclight_config, Config) ->
Config1 = inbox_helper:reload_inbox_option(Config, groupchat, [muclight]),
escalus:create_users(Config1, escalus:get_users([alice, alice_bis, bob, kate, mike]));
init_per_group(muc, Config) ->
muc_helper:load_muc(),
muc_helper:load_muc(Config),
inbox_helper:reload_inbox_option(Config, groupchat, [muc]);
init_per_group(limit_result, Config) ->
OptKey = [{modules, domain_helper:host_type()}, mod_inbox, max_result_limit],
Expand Down
2 changes: 1 addition & 1 deletion big_tests/tests/mam_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ suite() ->
require_rpc_nodes([mim]) ++ escalus:suite().

init_per_suite(Config) ->
muc_helper:load_muc(),
muc_helper:load_muc(Config),
mam_helper:prepare_for_suite(
increase_limits(
delete_users([{escalus_user_db, {module, escalus_ejabberd}}
Expand Down
2 changes: 1 addition & 1 deletion big_tests/tests/mod_event_pusher_rabbit_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ init_per_suite(Config) ->
true ->
start_rabbit_wpool(domain()),
{ok, _} = application:ensure_all_started(amqp_client),
muc_helper:load_muc(),
muc_helper:load_muc(Config),
escalus:init_per_suite(Config);
false ->
{skip, "RabbitMQ server is not available on default port."}
Expand Down
2 changes: 1 addition & 1 deletion big_tests/tests/mod_event_pusher_sns_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ init_per_suite(Config) ->
%% For mocking with unnamed functions
mongoose_helper:inject_module(?MODULE),

muc_helper:load_muc(),
muc_helper:load_muc(Config),
escalus:init_per_suite(Config);
{error, _} ->
{skip, "erlcloud dependency is not enabled"}
Expand Down
2 changes: 1 addition & 1 deletion big_tests/tests/mod_global_distrib_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ init_per_testcase(CaseName, Config)
{_, EuropeHost, _} = lists:keyfind(europe_node1, 1, get_hosts()),
trigger_rebalance(asia_node, EuropeHost),
%% Load muc on mim node
muc_helper:load_muc(),
muc_helper:load_muc(Config),
RegNode = ct:get_config({hosts, reg, node}),
%% Wait for muc.localhost to become visible from reg node
wait_for_domain(RegNode, muc_helper:muc_host()),
Expand Down
3 changes: 2 additions & 1 deletion big_tests/tests/mongoose_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ stop_online_rooms() ->
false -> ct:fail({ejabberd_mod_muc_sup_not_found, Supervisor, HostType})
end,
rpc(mim(), erlang, exit, [SupervisorPid, kill]),
rpc(mim(), mnesia, clear_table, [muc_online_room]),
%% That's a pretty dirty way
rpc(mim(), mongoose_muc_online_backend, clear_table, [HostType]),
ok.

forget_persistent_rooms() ->
Expand Down
6 changes: 2 additions & 4 deletions big_tests/tests/muc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

-import(muc_helper,
[muc_host/0,
load_muc/0,
unload_muc/0,
start_room/5,
generate_rpc_jid/1,
destroy_room/1,
Expand Down Expand Up @@ -331,14 +329,14 @@ init_per_suite(Config) ->
Config2 = escalus:init_per_suite(Config),
Config3 = dynamic_modules:save_modules(host_type(), Config2),
dynamic_modules:restart(host_type(), mod_disco, default_mod_config(mod_disco)),
load_muc(),
muc_helper:load_muc(Config),
mongoose_helper:ensure_muc_clean(),
Config3.

end_per_suite(Config) ->
escalus_fresh:clean(),
mongoose_helper:ensure_muc_clean(),
unload_muc(),
muc_helper:unload_muc(),
dynamic_modules:restore_modules(Config),
escalus:end_per_suite(Config).

Expand Down
27 changes: 21 additions & 6 deletions big_tests/tests/muc_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ foreach_recipient(Users, VerifyFun) ->
VerifyFun(escalus:wait_for_stanza(Recipient))
end, Users).

load_muc() ->
load_muc(domain_helper:host_type()).
load_muc(Config) ->
load_muc(Config, domain_helper:host_type()).

load_muc(HostType) ->
load_muc(Config, HostType) ->
Backend = muc_backend(),
MucHostPattern = ct:get_config({hosts, mim, muc_service_pattern}),
ct:log("Starting MUC for ~p", [HostType]),
Opts = #{host => subhost_pattern(MucHostPattern), backend => Backend,
online_backend => muc_online_backend(Config),
hibernate_timeout => 2000,
hibernated_room_check_interval => 1000,
hibernated_room_timeout => 2000,
Expand All @@ -86,6 +87,9 @@ muc_host_pattern() ->
muc_backend() ->
mongoose_helper:mnesia_or_rdbms_backend().

muc_online_backend(Config) when is_list(Config) ->
ct_helper:get_preset_var(Config, muc_online_backend, mnesia).

start_room(Config, User, Room, Nick, Opts) ->
From = generate_rpc_jid(User),
create_instant_room(Room, From, Nick, Opts),
Expand Down Expand Up @@ -176,15 +180,26 @@ destroy_room(Config) ->
destroy_room(muc_host(), ?config(room, Config)).

destroy_room(Host, Room) when is_binary(Host), is_binary(Room) ->
HostType = domain_helper:host_type(),
Room1 = jid:nodeprep(Room),
case rpc(mim(), ets, lookup, [muc_online_room, {Room1, Host}]) of
[{_,_,Pid}|_] ->
case rpc(mim(), mongoose_muc_online_backend, find_room_pid, [HostType, Host, Room1]) of
{ok, Pid} ->
%% @TODO related to gen_fsm_compat: after migration to gen_statem
%% should be replaced to - gen_statem:call(Pid, destroy).
Pid ! {'$gen_all_state_event', destroy},
wait_for_process_down(Pid),
ok;
_ ->
{error, not_found} ->
ok
end.

wait_for_process_down(Pid) ->
Ref = monitor(process, Pid),
receive
{'DOWN', Ref, _Type, Pid, _Info} ->
ok
after 5000 ->
ct:fail(wait_for_process_down_failed)
end.

stanza_muc_enter_room(Room, Nick) ->
Expand Down
2 changes: 1 addition & 1 deletion big_tests/tests/muc_http_api_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ failure_response() ->
%%--------------------------------------------------------------------

init_per_suite(Config) ->
muc_helper:load_muc(),
muc_helper:load_muc(Config),
escalus:init_per_suite(Config).

end_per_suite(Config) ->
Expand Down
5 changes: 0 additions & 5 deletions include/mod_muc.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,3 @@
host_type,
pid
}).

-record(muc_registered, {
us_host,
nick
}).
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.9.0">>},1},
{<<"cets">>,
{git,"https://github.com/esl/cets.git",
{ref,"458e2e1df3fb51896fe334385bb0d2c9c53ef87f"}},
{ref,"7d4876fe5285118f5349970ffb20080ea62293db"}},
0},
{<<"cowboy">>,{pkg,<<"cowboy">>,<<"2.9.0">>},0},
{<<"cowboy_swagger">>,{pkg,<<"cowboy_swagger">>,<<"2.5.1">>},0},
Expand Down
10 changes: 8 additions & 2 deletions src/hooks/mongoose_hooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@
mod_global_distrib_unknown_recipient/2]).

-export([remove_domain/2,
node_cleanup/1]).
node_cleanup/1,
node_cleanup_for_host_type/2]).

-ignore_xref([node_cleanup/1, remove_domain/2]).
-ignore_xref([remove_domain/2]).
-ignore_xref([mam_archive_sync/1, mam_muc_archive_sync/1]).

%% Just a map, used by some hooks as a first argument.
Expand Down Expand Up @@ -217,6 +218,11 @@ node_cleanup(Node) ->
Params = #{node => Node},
run_global_hook(node_cleanup, #{}, Params).

-spec node_cleanup_for_host_type(HostType :: mongooseim:host_type(), Node :: node()) -> Acc :: map().
node_cleanup_for_host_type(HostType, Node) ->
Params = #{node => Node},
run_hook_for_host_type(node_cleanup_for_host_type, HostType, #{}, Params).

-spec failed_to_store_message(Acc) -> Result when
Acc :: mongoose_acc:t(),
Result :: mongoose_acc:t().
Expand Down
Loading

0 comments on commit 3407849

Please sign in to comment.