Skip to content

Commit

Permalink
Merge pull request #4063 from esl/feature/cets
Browse files Browse the repository at this point in the history
Feature/cets
  • Loading branch information
NelsonVides authored Aug 8, 2023
2 parents 97fd327 + c5faa49 commit 257371d
Show file tree
Hide file tree
Showing 140 changed files with 4,018 additions and 1,817 deletions.
11 changes: 10 additions & 1 deletion .circleci/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ jobs:
preset:
type: enum
enum: [internal_mnesia, mysql_redis, odbc_mssql_mnesia, ldap_mnesia,
elasticsearch_and_cassandra_mnesia, pgsql_mnesia]
elasticsearch_and_cassandra_mnesia, pgsql_mnesia, pgsql_cets]
description: Preset to run
default: internal_mnesia
db:
Expand Down Expand Up @@ -865,6 +865,15 @@ workflows:
requires:
- otp_25_docker
filters: *all_tags
- big_tests_in_docker:
name: pgsql_cets_25
executor: otp_25_pgsql_redis
context: mongooseim-org
preset: pgsql_cets
db: "mnesia postgres cets"
requires:
- otp_25_docker
filters: *all_tags
- big_tests_in_docker:
name: mysql_redis_25
executor: otp_25_mysql_redis
Expand Down
3 changes: 3 additions & 0 deletions big_tests/default.spec
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
{suites, "tests", graphql_gdpr_SUITE}.
{suites, "tests", graphql_token_SUITE}.
{suites, "tests", graphql_mnesia_SUITE}.
{suites, "tests", graphql_cets_SUITE}.
{suites, "tests", graphql_vcard_SUITE}.
{suites, "tests", graphql_http_upload_SUITE}.
{suites, "tests", graphql_server_SUITE}.
Expand Down Expand Up @@ -115,6 +116,8 @@
{suites, "tests", dynamic_domains_SUITE}.
{suites, "tests", local_iq_SUITE}.
{suites, "tests", tcp_listener_SUITE}.
{suites, "tests", cets_disco_SUITE}.
{suites, "tests", start_node_id_SUITE}.

{config, ["test.config"]}.
{logdir, "ct_report"}.
Expand Down
3 changes: 3 additions & 0 deletions big_tests/dynamic_domains.spec
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
{suites, "tests", graphql_gdpr_SUITE}.
{suites, "tests", graphql_token_SUITE}.
{suites, "tests", graphql_mnesia_SUITE}.
{suites, "tests", graphql_cets_SUITE}.
{suites, "tests", graphql_http_upload_SUITE}.
{suites, "tests", graphql_server_SUITE}.
{suites, "tests", graphql_metric_SUITE}.
Expand Down Expand Up @@ -157,6 +158,8 @@
{suites, "tests", domain_removal_SUITE}.
{suites, "tests", local_iq_SUITE}.
{suites, "tests", tcp_listener_SUITE}.
{suites, "tests", cets_disco_SUITE}.
{suites, "tests", start_node_id_SUITE}.

{config, ["dynamic_domains.config", "test.config"]}.

Expand Down
13 changes: 13 additions & 0 deletions big_tests/src/mim_loglevel.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
-module(mim_loglevel).
-export([enable_logging/2]).
-export([disable_logging/2]).
-export([save_log_level/1]).
-export([restore_log_level/1]).

enable_logging(Hosts, Levels) ->
[set_custom(Host, Module, Level) || Host <- Hosts, {Module, Level} <- Levels].
Expand All @@ -15,3 +17,14 @@ set_custom(Host, Module, Level) ->
clear_custom(Host, Module, _Level) ->
Node = ct:get_config({hosts, Host, node}),
mongoose_helper:successful_rpc(#{node => Node}, mongoose_logs, clear_module_loglevel, [Module]).

save_log_level(Config) ->
Node = distributed_helper:mim(),
OldLogLevel = distributed_helper:rpc(Node, mongoose_logs, get_global_loglevel, []),
[{old_log_level, OldLogLevel} | Config].

restore_log_level(Config) ->
Node = distributed_helper:mim(),
{old_log_level, OldLogLevel} = lists:keyfind(old_log_level, 1, Config),
ok = distributed_helper:rpc(Node, mongoose_logs, set_global_loglevel, [OldLogLevel]),
ok.
30 changes: 30 additions & 0 deletions big_tests/test.config
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,36 @@
{outgoing_pools, "[outgoing_pools.redis.global_distrib]
scope = \"global\"
workers = 10"}]},
{pgsql_cets,
[{dbs, [redis, pgsql]},
{sm_backend, "\"cets\""},
{bosh_backend, "\"cets\""},
{component_backend, "\"cets\""},
{s2s_backend, "\"cets\""},
{stream_management_backend, cets},
{muc_online_backend, cets},
{jingle_sip_backend, cets},
{auth_method, "rdbms"},
{internal_databases, "[internal_databases.cets]
cluster_name = \"{{cluster_name}}\""},
{outgoing_pools, "[outgoing_pools.redis.global_distrib]
scope = \"global\"
workers = 10
[outgoing_pools.rdbms.default]
scope = \"global\"
workers = 5
connection.driver = \"pgsql\"
connection.host = \"localhost\"
connection.database = \"ejabberd\"
connection.username = \"ejabberd\"
connection.password = \"mongooseim_secret\"
connection.tls.required = true
connection.tls.cacertfile = \"priv/ssl/cacert.pem\"
connection.tls.server_name_indication.enabled = false"},
{service_domain_db, ""},
{mod_vcard, " backend = \"rdbms\"
host = \"vjud.@HOST@\"\n"},
{mod_roster, " backend = \"rdbms\"\n"}]},
{pgsql_mnesia,
[{dbs, [redis, pgsql]},
{auth_method, "rdbms"},
Expand Down
76 changes: 76 additions & 0 deletions big_tests/tests/cets_disco_SUITE.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
-module(cets_disco_SUITE).
-compile([export_all, nowarn_export_all]).

-import(distributed_helper, [mim/0, rpc/4]).
-include_lib("common_test/include/ct.hrl").

%%--------------------------------------------------------------------
%% Suite configuration
%%--------------------------------------------------------------------

all() ->
[{group, file}, {group, rdbms}].

groups() ->
[{file, [], file_cases()},
{rdbms, [], rdbms_cases()}].

file_cases() ->
[file_backend].

rdbms_cases() ->
[rdbms_backend].

suite() ->
escalus:suite().

%%--------------------------------------------------------------------
%% Init & teardown
%%--------------------------------------------------------------------
init_per_suite(Config) ->
escalus:init_per_suite(Config).

end_per_suite(Config) ->
escalus:end_per_suite(Config).

init_per_group(rdbms, Config) ->
case not ct_helper:is_ct_running()
orelse mongoose_helper:is_rdbms_enabled(domain_helper:host_type()) of
false -> {skip, rdbms_or_ct_not_running};
true -> Config
end;
init_per_group(_, Config) ->
Config.

end_per_group(_, Config) ->
Config.

init_per_testcase(CaseName, Config) ->
escalus:init_per_testcase(CaseName, Config).

end_per_testcase(CaseName, Config) ->
escalus:end_per_testcase(CaseName, Config).

%%--------------------------------------------------------------------
%% Test cases
%%--------------------------------------------------------------------

file_backend(Config) ->
Path = filename:join(?config(mim_data_dir, Config), "nodes.txt"),
Opts = #{disco_file => Path},
State = rpc(mim(), cets_discovery_file, init, [Opts]),
{{ok, Nodes}, _} = rpc(mim(), cets_discovery_file, get_nodes, [State]),
['node1@localhost', 'node2@otherhost'] = lists:sort(Nodes).

rdbms_backend(_Config) ->
Opts1 = #{cluster_name => <<"big_test">>, node_name_to_insert => <<"test1">>},
Opts2 = #{cluster_name => <<"big_test">>, node_name_to_insert => <<"test2">>},
State1 = rpc(mim(), mongoose_cets_discovery_rdbms, init, [Opts1]),
rpc(mim(), mongoose_cets_discovery_rdbms, get_nodes, [State1]),
State2 = rpc(mim(), mongoose_cets_discovery_rdbms, init, [Opts2]),
{{ok, Nodes}, State2_2} = rpc(mim(), mongoose_cets_discovery_rdbms, get_nodes, [State2]),
%% "test2" node can see "test1"
true = lists:member(test1, Nodes),
{{ok, _}, State2_3} = rpc(mim(), mongoose_cets_discovery_rdbms, get_nodes, [State2_2]),
%% Check that we follow the right code branch
#{last_query_info := #{already_registered := true}} = State2_3.
2 changes: 2 additions & 0 deletions big_tests/tests/cets_disco_SUITE_data/nodes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node1@localhost
node2@otherhost
2 changes: 1 addition & 1 deletion big_tests/tests/component_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ disconnect_component(Component, Addr) ->
disconnect_components(Components, Addr) ->
%% TODO replace 'kill' with 'stop' when server supports stream closing
[escalus_connection:kill(Component) || Component <- Components],
mongoose_helper:wait_until(fun() -> rpc(ejabberd_router, lookup_component, [Addr]) =:= [] end, true,
mongoose_helper:wait_until(fun() -> rpc(mongoose_component, lookup_component, [Addr]) =:= [] end, true,
#{name => rpc}).

rpc(M, F, A) ->
Expand Down
12 changes: 11 additions & 1 deletion big_tests/tests/ct_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
repeat_all_until_all_ok/2,
repeat_all_until_any_fail/1,
repeat_all_until_any_fail/2,
groups_to_all/1]).
groups_to_all/1,
get_preset_var/3]).

-type group_name() :: atom().

Expand Down Expand Up @@ -114,3 +115,12 @@ is_ct_started() ->

groups_to_all(Groups) ->
[{group, Name} || {Name, _Opts, _Cases} <- Groups].

get_preset_var(Config, Opt, Def) ->
case proplists:get_value(preset, Config, undefined) of
Preset ->
PresetAtom = list_to_existing_atom(Preset),
ct:get_config({presets, toml, PresetAtom, Opt}, Def);
_ ->
Def
end.
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
77 changes: 77 additions & 0 deletions big_tests/tests/graphql_cets_SUITE.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
-module(graphql_cets_SUITE).
-include_lib("eunit/include/eunit.hrl").

-compile([export_all, nowarn_export_all]).

-import(distributed_helper, [mim/0]).
-import(domain_helper, [host_type/1]).
-import(mongooseimctl_helper, [rpc_call/3]).
-import(graphql_helper, [execute_command/4, get_unauthorized/1, get_ok_value/2]).

all() ->
[{group, admin_cets_cli},
{group, admin_cets_http},
{group, domain_admin_cets}].

groups() ->
[{admin_cets_http, [sequence], admin_cets_tests()},
{admin_cets_cli, [sequence], admin_cets_tests()},
{domain_admin_cets, [], domain_admin_tests()}].

admin_cets_tests() ->
[has_sm_table_in_info].

domain_admin_tests() ->
[domain_admin_get_info_test].

init_per_suite(Config) ->
Config1 = escalus:init_per_suite(Config),
ejabberd_node_utils:init(mim(), Config1).

end_per_suite(Config) ->
escalus:end_per_suite(Config).

init_per_group(admin_cets_http, Config) ->
graphql_helper:init_admin_handler(Config);
init_per_group(admin_cets_cli, Config) ->
graphql_helper:init_admin_cli(Config);
init_per_group(domain_admin_cets, Config) ->
graphql_helper:init_domain_admin_handler(Config).

end_per_group(_, _Config) ->
graphql_helper:clean(),
escalus_fresh:clean().

init_per_testcase(has_sm_table_in_info, Config) ->
case rpc_call(ejabberd_sm, sm_backend, []) of
ejabberd_sm_cets ->
Config;
_ ->
{skip, "SM backend is not CETS"}
end;
init_per_testcase(_, Config) ->
Config.

% Admin tests

has_sm_table_in_info(Config) ->
Res = get_info(Config),
Tables = get_ok_value([data, cets, systemInfo], Res),
[T] = [T || T = #{<<"tableName">> := <<"cets_session">>} <- Tables],
#{<<"memory">> := Mem, <<"nodes">> := Nodes, <<"size">> := Size} = T,
true = is_integer(Mem),
true = is_integer(Size),
#{node := Node1} = mim(),
lists:member(Node1, Nodes).

% Domain admin tests

domain_admin_get_info_test(Config) ->
get_unauthorized(get_info(Config)).

%--------------------------------------------------------------------------------------------------
% Helpers
%--------------------------------------------------------------------------------------------------

get_info(Config) ->
execute_command(<<"cets">>, <<"systemInfo">>, #{}, Config).
11 changes: 8 additions & 3 deletions big_tests/tests/graphql_metric_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,13 @@ get_cluster_metrics_by_nonexistent_name(Config) ->
Result = get_cluster_metrics_as_dicts_by_name([<<"nonexistent">>], Config),
ParsedResult = get_ok_value([data, metric, getClusterMetricsAsDicts], Result),
[#{<<"node">> := _, <<"result">> := []},
#{<<"node">> := _, <<"result">> := []}] = ParsedResult.
#{<<"node">> := _, <<"result">> := []}|_] = ParsedResult. %% two or three nodes.

get_cluster_metrics_with_nonexistent_key(Config) ->
Result = get_cluster_metrics_as_dicts_with_keys([<<"nonexistent">>], Config),
ParsedResult = get_ok_value([data, metric, getClusterMetricsAsDicts], Result),
[#{<<"node">> := _, <<"result">> := [_|_]},
#{<<"node">> := _, <<"result">> := [_|_]}] = ParsedResult.
#{<<"node">> := _, <<"result">> := [_|_]}|_] = ParsedResult.

get_cluster_metrics_empty_args(Config) ->
Node = atom_to_binary(maps:get(node, distributed_helper:mim2())),
Expand Down Expand Up @@ -445,7 +445,12 @@ check_spiral_dict(Dict) ->
?assert(is_integer(One)).

values_are_integers(Map, Keys) ->
lists:foreach(fun(Key) -> ?assert(is_integer(maps:get(Key, Map))) end, Keys).
case lists:all(fun(Key) -> is_integer(maps:get(Key, Map)) end, Keys) of
true ->
ok;
false ->
ct:fail({values_are_integers, Keys, Map})
end.

metric_host_type() ->
binary:replace(domain_helper:host_type(), <<" ">>, <<"_">>, [global]).
Loading

0 comments on commit 257371d

Please sign in to comment.