From a69e21a253a420bfec98d7e373ed34c0004267e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Fri, 24 Sep 2021 10:06:41 +0200 Subject: [PATCH 1/4] Reorganize helpers --- big_tests/tests/domain_removal_SUITE.erl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/big_tests/tests/domain_removal_SUITE.erl b/big_tests/tests/domain_removal_SUITE.erl index 7bb505ce32..e337145124 100644 --- a/big_tests/tests/domain_removal_SUITE.erl +++ b/big_tests/tests/domain_removal_SUITE.erl @@ -116,10 +116,6 @@ auth_removal(Config) -> connect_and_disconnect(AliceBisSpec), % different domain - not removed ?assertEqual([], rpc(mim(), ejabberd_auth, get_vh_registered_users, [domain()])). -connect_and_disconnect(Spec) -> - {ok, Client, _} = escalus_connection:start(Spec), - escalus_connection:stop(Client). - mam_pm_removal(Config) -> F = fun(Alice, Bob) -> escalus:send(Alice, escalus_stanza:chat_to(Bob, <<"OH, HAI!">>)), @@ -260,6 +256,12 @@ roster_removal(Config) -> ?assertMatch([], select_from_roster("roster_version")) end). +%% Helpers + +connect_and_disconnect(Spec) -> + {ok, Client, _} = escalus_connection:start(Spec), + escalus_connection:stop(Client). + select_from_roster(Table) -> Query = "SELECT * FROM " ++ Table ++ " WHERE server='" ++ binary_to_list(domain()) ++ "'", {selected, Res} = rpc(mim(), mongoose_rdbms, sql_query, [host_type(), Query]), From 116074422a6218e103604fb676ad915b09699577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Fri, 24 Sep 2021 15:43:38 +0200 Subject: [PATCH 2/4] Test domain removal for mod_cache_users --- big_tests/tests/domain_removal_SUITE.erl | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/big_tests/tests/domain_removal_SUITE.erl b/big_tests/tests/domain_removal_SUITE.erl index e337145124..a4f1bf2ed7 100644 --- a/big_tests/tests/domain_removal_SUITE.erl +++ b/big_tests/tests/domain_removal_SUITE.erl @@ -14,6 +14,7 @@ all() -> [{group, auth_removal}, + {group, cache_removal}, {group, mam_removal}, {group, inbox_removal}, {group, muc_light_removal}, @@ -24,6 +25,7 @@ all() -> groups() -> [ {auth_removal, [], [auth_removal]}, + {cache_removal, [], [cache_removal]}, {mam_removal, [], [mam_pm_removal, mam_muc_removal]}, {inbox_removal, [], [inbox_removal]}, @@ -66,6 +68,9 @@ end_per_group(_Groupname, Config) -> end, ok. +group_to_modules(cache_removal) -> + [{mod_cache_users, []}, + {mod_mam_meta, [{backend, rdbms}, {pm, []}]}]; group_to_modules(mam_removal) -> MucHost = subhost_pattern(muc_light_helper:muc_host_pattern()), [{mod_mam_meta, [{backend, rdbms}, {pm, []}, {muc, [{host, MucHost}]}]}, @@ -116,6 +121,23 @@ auth_removal(Config) -> connect_and_disconnect(AliceBisSpec), % different domain - not removed ?assertEqual([], rpc(mim(), ejabberd_auth, get_vh_registered_users, [domain()])). +cache_removal(Config) -> + FreshConfig = escalus_fresh:create_users(Config, [{alice, 1}, {alice_bis, 1}]), + F = fun(Alice, AliceBis) -> + escalus:send(Alice, escalus_stanza:chat_to(AliceBis, <<"Hi!">>)), + escalus:wait_for_stanza(AliceBis), + mam_helper:wait_for_archive_size(Alice, 1), + mam_helper:wait_for_archive_size(AliceBis, 1) + end, + escalus:story(FreshConfig, [{alice, 1}, {alice_bis, 1}], F), + %% Storing the message in MAM should have populated the cache for both users + ?assertEqual({stop, true}, does_cached_user_exist(FreshConfig, alice)), + ?assertEqual({stop, true}, does_cached_user_exist(FreshConfig, alice_bis)), + run_remove_domain(), + %% Cache removed only for Alice's domain + ?assertEqual(false, does_cached_user_exist(FreshConfig, alice)), + ?assertEqual({stop, true}, does_cached_user_exist(FreshConfig, alice_bis)). + mam_pm_removal(Config) -> F = fun(Alice, Bob) -> escalus:send(Alice, escalus_stanza:chat_to(Bob, <<"OH, HAI!">>)), @@ -262,6 +284,10 @@ connect_and_disconnect(Spec) -> {ok, Client, _} = escalus_connection:start(Spec), escalus_connection:stop(Client). +does_cached_user_exist(Config, User) -> + Jid = jid:from_binary(escalus_users:get_jid(Config, User)), + rpc(mim(), mod_cache_users, does_cached_user_exist, [false, host_type(), Jid, stored]). + select_from_roster(Table) -> Query = "SELECT * FROM " ++ Table ++ " WHERE server='" ++ binary_to_list(domain()) ++ "'", {selected, Res} = rpc(mim(), mongoose_rdbms, sql_query, [host_type(), Query]), From 03692d693fcd53d6df55a9b976f942f64cc97320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Fri, 24 Sep 2021 15:49:54 +0200 Subject: [PATCH 3/4] Reorder 'groups_to_modules' according to the test cases --- big_tests/tests/domain_removal_SUITE.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/big_tests/tests/domain_removal_SUITE.erl b/big_tests/tests/domain_removal_SUITE.erl index a4f1bf2ed7..804b129d0d 100644 --- a/big_tests/tests/domain_removal_SUITE.erl +++ b/big_tests/tests/domain_removal_SUITE.erl @@ -68,6 +68,8 @@ end_per_group(_Groupname, Config) -> end, ok. +group_to_modules(auth_removal) -> + []; group_to_modules(cache_removal) -> [{mod_cache_users, []}, {mod_mam_meta, [{backend, rdbms}, {pm, []}]}]; @@ -84,8 +86,6 @@ group_to_modules(private_removal) -> [{mod_private, [{backend, rdbms}]}]; group_to_modules(roster_removal) -> [{mod_roster, [{backend, rdbms}]}]; -group_to_modules(auth_removal) -> - []; group_to_modules(offline_removal) -> [{mod_offline, [{backend, rdbms}]}]. From 31536fb8751bc8c8951eea1f586c58d8637f07ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Mon, 27 Sep 2021 15:31:37 +0200 Subject: [PATCH 4/4] Determine the host type dynamically This is needed to make the test work with static and dynamic domains, which have different host type configurations: - One host type for dynamic domains - Two host types for static domains --- big_tests/tests/domain_helper.erl | 5 +++++ big_tests/tests/domain_removal_SUITE.erl | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/big_tests/tests/domain_helper.erl b/big_tests/tests/domain_helper.erl index e44da44055..a18e76d1fc 100644 --- a/big_tests/tests/domain_helper.erl +++ b/big_tests/tests/domain_helper.erl @@ -9,6 +9,7 @@ host_types/1, host_type/0, host_type/1, + domain_to_host_type/2, domain/0, domain/1, secondary_host_type/0, @@ -31,6 +32,10 @@ domain() -> host_type(NodeKey) -> get_or_fail({hosts, NodeKey, host_type}). +domain_to_host_type(Node, Domain) -> + {ok, HostType} = rpc(Node, mongoose_domain_core, get_host_type, [Domain]), + HostType. + domain(NodeKey) -> get_or_fail({hosts, NodeKey, domain}). diff --git a/big_tests/tests/domain_removal_SUITE.erl b/big_tests/tests/domain_removal_SUITE.erl index 804b129d0d..274f10db8c 100644 --- a/big_tests/tests/domain_removal_SUITE.erl +++ b/big_tests/tests/domain_removal_SUITE.erl @@ -3,14 +3,12 @@ -compile([export_all, nowarn_export_all]). -import(distributed_helper, [mim/0, rpc/4, subhost_pattern/1]). --import(domain_helper, [host_type/0, domain/0]). +-import(domain_helper, [host_type/0, domain_to_host_type/2, domain/0]). -include("mam_helper.hrl"). --include_lib("escalus/include/escalus.hrl"). --include_lib("escalus/include/escalus_xmlns.hrl"). --include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). -include_lib("exml/include/exml_stream.hrl"). +-include_lib("jid/include/jid.hrl"). all() -> [{group, auth_removal}, @@ -52,8 +50,10 @@ end_per_suite(Config) -> init_per_group(Group, Config) -> case mongoose_helper:is_rdbms_enabled(host_type()) of true -> - Config2 = dynamic_modules:save_modules(host_type(), Config), - rpc(mim(), gen_mod_deps, start_modules, [host_type(), group_to_modules(Group)]), + HostTypes = domain_helper:host_types(), + Config2 = dynamic_modules:save_modules_for_host_types(HostTypes, Config), + [dynamic_modules:ensure_modules(HostType, group_to_modules(Group)) || + HostType <- HostTypes], Config2; false -> {skip, require_rdbms} @@ -62,7 +62,7 @@ init_per_group(Group, Config) -> end_per_group(_Groupname, Config) -> case mongoose_helper:is_rdbms_enabled(host_type()) of true -> - dynamic_modules:restore_modules(host_type(), Config); + dynamic_modules:restore_modules(Config); false -> ok end, @@ -285,8 +285,9 @@ connect_and_disconnect(Spec) -> escalus_connection:stop(Client). does_cached_user_exist(Config, User) -> - Jid = jid:from_binary(escalus_users:get_jid(Config, User)), - rpc(mim(), mod_cache_users, does_cached_user_exist, [false, host_type(), Jid, stored]). + Jid = #jid{server = Domain} = jid:from_binary(escalus_users:get_jid(Config, User)), + HostType = domain_to_host_type(mim(), Domain), + rpc(mim(), mod_cache_users, does_cached_user_exist, [false, HostType, Jid, stored]). select_from_roster(Table) -> Query = "SELECT * FROM " ++ Table ++ " WHERE server='" ++ binary_to_list(domain()) ++ "'",