Skip to content

Commit

Permalink
Merge pull request #3279 from esl/test-mam-send-message-with-dynamic-…
Browse files Browse the repository at this point in the history
…domains
  • Loading branch information
vkatsuba authored Sep 17, 2021
2 parents a674c09 + 128bb3f commit 3ad1bfd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
2 changes: 2 additions & 0 deletions big_tests/dynamic_domains.spec
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

{suites, "tests", mam_SUITE}.

{suites, "tests", mam_send_message_SUITE}.

{suites, "tests", metrics_register_SUITE}.

{suites, "tests", mod_blocking_SUITE}.
Expand Down
17 changes: 8 additions & 9 deletions big_tests/tests/mam_send_message_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
require_rpc_nodes/1,
subhost_pattern/1,
rpc/4]).
-import(domain_helper, [host_type/0]).

-include("mam_helper.hrl").
-include_lib("escalus/include/escalus.hrl").
Expand All @@ -40,9 +41,6 @@ groups() ->
mam_muc_send_message]}
].

domain() ->
ct:get_config({hosts, mim, domain}).

%%%===================================================================
%%% Overall setup/teardown
%%%===================================================================
Expand All @@ -57,20 +55,20 @@ end_per_suite(Config) ->
%%% Group specific setup/teardown
%%%===================================================================
init_per_group(Group, Config) ->
case mongoose_helper:is_rdbms_enabled(domain()) of
case mongoose_helper:is_rdbms_enabled(host_type()) of
true ->
load_custom_module(),
Config2 = dynamic_modules:save_modules(domain(), Config),
rpc(mim(), gen_mod_deps, start_modules, [domain(), group_to_modules(Group)]),
Config2 = dynamic_modules:save_modules(host_type(), Config),
rpc(mim(), gen_mod_deps, start_modules, [host_type(), group_to_modules(Group)]),
[{props, mam_helper:mam06_props()}|Config2];
false ->
{skip, require_rdbms}
end.

end_per_group(_Groupname, Config) ->
case mongoose_helper:is_rdbms_enabled(domain()) of
case mongoose_helper:is_rdbms_enabled(host_type()) of
true ->
dynamic_modules:restore_modules(domain(), Config);
dynamic_modules:restore_modules(host_type(), Config);
false ->
ok
end,
Expand All @@ -80,7 +78,8 @@ group_to_modules(send_message) ->
MH = subhost_pattern(muc_light_helper:muc_host_pattern()),
[{mod_mam_meta, [{backend, rdbms}, {pm, []}, {muc, [{host, MH}]},
{send_message, mam_send_message_example}]},
{mod_muc_light, []},
{mod_muc_light, [{host, subhost_pattern(muc_light_helper:muc_host_pattern())},
{backend, mongoose_helper:mnesia_or_rdbms_backend()}]},
{mam_send_message_example, []}].

load_custom_module() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@

-export([start/2,
stop/1,
supported_features/0,
lookup_messages/3,
send_message/4]).


start(Host, _Opts) ->
ejabberd_hooks:add(hooks(Host)).
start(HostType, _Opts) ->
ejabberd_hooks:add(hooks(HostType)).

stop(Host) ->
ejabberd_hooks:delete(hooks(Host)).
stop(HostType) ->
ejabberd_hooks:delete(hooks(HostType)).

hooks(Host) ->
[{mam_lookup_messages, Host, ?MODULE, lookup_messages, 60},
{mam_muc_lookup_messages, Host, ?MODULE, lookup_messages, 60}].
supported_features() ->
[dynamic_domains].

hooks(HostType) ->
[{mam_lookup_messages, HostType, ?MODULE, lookup_messages, 60},
{mam_muc_lookup_messages, HostType, ?MODULE, lookup_messages, 60}].

%% caller_jid could be used for privacy checking or per-user customization
lookup_messages({error, _Reason} = Result, _Host, _Params) ->
Result;
lookup_messages({ok, {TotalCount, Offset, MessageRows}},
Host, Params = #{owner_jid := ArcJID, caller_jid := _CallerJID}) ->
Host, _Params = #{owner_jid := ArcJID, caller_jid := _CallerJID}) ->
MessageRows2 = [extend_message(Host, ArcJID, Row) || Row <- MessageRows],
{ok, {TotalCount, Offset, MessageRows2}}.

Expand Down

0 comments on commit 3ad1bfd

Please sign in to comment.