Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Dec 6, 2021
1 parent 99ddcc3 commit c909eac
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 55 deletions.
21 changes: 12 additions & 9 deletions big_tests/tests/mam_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ init_modules(rdbms_simple, C, Config) when C =:= muc_all;
init_modules(rdbms_async_pool, C, Config) when C =:= muc_all;
C =:= muc_disabled_retraction ->
init_module(host_type(), mod_mam_muc_rdbms_arch, [no_writer]),
init_module(host_type(), mod_mam_muc_rdbms_async_pool_writer, [{flush_interval, 1}]), %% 1ms
init_module(host_type(), mod_mam_rdbms_arch_async, [{muc, [{flush_interval, 1}]}]), %% 1ms
init_module(host_type(), mod_mam_rdbms_prefs, [muc]),
init_module(host_type(), mod_mam_rdbms_user, [muc, pm]),
init_module(host_type(), mod_mam_muc, [{host, subhost_pattern(muc_domain(Config))}] ++
Expand All @@ -719,7 +719,7 @@ init_modules(rdbms_cache, C, Config) when C =:= muc_all;
init_modules(rdbms_async_cache, C, Config) when C =:= muc_all;
C =:= muc_disabled_retraction ->
init_module(host_type(), mod_mam_muc_rdbms_arch, [no_writer]),
init_module(host_type(), mod_mam_muc_rdbms_async_pool_writer, [{flush_interval, 1}]), %% 1ms
init_module(host_type(), mod_mam_rdbms_arch_async, [{muc, [{flush_interval, 1}]}]), %% 1ms
init_module(host_type(), mod_mam_rdbms_prefs, [muc]),
init_module(host_type(), mod_mam_rdbms_user, [muc, pm]),
init_module(host_type(), mod_mam_cache_user, [muc]),
Expand Down Expand Up @@ -787,7 +787,7 @@ init_modules(elasticsearch, C, Config) ->
init_modules(rdbms_async_pool, C, Config) ->
init_module(host_type(), mod_mam, addin_mam_options(C, Config)),
init_module(host_type(), mod_mam_rdbms_arch, [no_writer]),
init_module(host_type(), mod_mam_rdbms_async_pool_writer, [pm, {flush_interval, 1}]), %% 1ms
init_module(host_type(), mod_mam_rdbms_arch_async, [{pm, [{flush_interval, 1}]}]), %% 1ms
init_module(host_type(), mod_mam_rdbms_prefs, [pm]),
init_module(host_type(), mod_mam_rdbms_user, [pm]),
Config;
Expand All @@ -807,7 +807,7 @@ init_modules(rdbms_cache, C, Config) ->
init_modules(rdbms_async_cache, C, Config) ->
init_module(host_type(), mod_mam, addin_mam_options(C, Config)),
init_module(host_type(), mod_mam_rdbms_arch, [no_writer]),
init_module(host_type(), mod_mam_rdbms_async_pool_writer, [pm, {flush_interval, 1}]), %% 1ms
init_module(host_type(), mod_mam_rdbms_arch_async, [{pm, [{flush_interval, 1}]}]), %% 1ms
init_module(host_type(), mod_mam_rdbms_prefs, [pm]),
init_module(host_type(), mod_mam_rdbms_user, [pm]),
init_module(host_type(), mod_mam_cache_user, [pm]),
Expand Down Expand Up @@ -862,8 +862,7 @@ mam_modules() ->
mod_mam_muc_elasticsearch_arch,
mod_mam_rdbms_arch,
mod_mam_muc_rdbms_arch,
mod_mam_rdbms_async_pool_writer,
mod_mam_muc_rdbms_async_pool_writer,
mod_mam_rdbms_arch_async,
mod_mam_rdbms_prefs,
mod_mam_mnesia_prefs,
mod_mam_rdbms_user,
Expand Down Expand Up @@ -1162,10 +1161,14 @@ required_modules(retract_message_on_stanza_id, _Config) ->
required_modules(_, _) ->
[].

init_module(Host, mod_mam_rdbms_arch_async, Args) ->
OldOpts = case stop_module(Host, mod_mam_rdbms_arch_async) of
{ok, O} -> O;
ok -> []
end,
{ok, _} = start_module(Host, mod_mam_rdbms_arch_async, lists:ukeymerge(1, OldOpts, Args));
init_module(Host, Mod, Args) ->
lists:member(Mod, mam_modules())
orelse
ct:fail("Unknown module ~p", [Mod]),
lists:member(Mod, mam_modules()) orelse ct:fail("Unknown module ~p", [Mod]),
stop_module(Host, Mod),
{ok, _} = start_module(Host, Mod, Args).

Expand Down
61 changes: 32 additions & 29 deletions test/config_parser_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,8 @@ mod_mam_meta_muc(_Config) ->
?errh(T(#{<<"same_mam_id_for_peers">> => true})).

test_mod_mam_meta(T, M) ->
test_async_worker(T, M),
test_cache_config(T, M),
?cfgh(M([{backend, rdbms}]),
T(#{<<"backend">> => <<"rdbms">>})),
?cfgh(M([{no_stanzaid_element, true}]),
Expand All @@ -2023,18 +2025,8 @@ test_mod_mam_meta(T, M) ->
T(#{<<"archive_chat_markers">> => false})),
?cfgh(M([{message_retraction, true}]),
T(#{<<"message_retraction">> => true})),
?cfgh(M([{cache_users, false}]),
T(#{<<"cache_users">> => false})),
?cfgh(M([{rdbms_message_format, simple}]),
T(#{<<"rdbms_message_format">> => <<"simple">>})),
?cfgh(M([{async_writer, true}]),
T(#{<<"async_writer">> => true})),
?cfgh(M([{flush_interval, 1500}]),
T(#{<<"flush_interval">> => 1500})),
?cfgh(M([{max_batch_size, 50}]),
T(#{<<"max_batch_size">> => 50})),
?cfgh(M([{pool_size, 50}]),
T(#{<<"pool_size">> => 50})),
?cfgh(M([{user_prefs_store, rdbms}]),
T(#{<<"user_prefs_store">> => <<"rdbms">>})),
?cfgh(M([{full_text_search, false}]),
Expand All @@ -2043,8 +2035,6 @@ test_mod_mam_meta(T, M) ->
T(#{<<"default_result_limit">> => 100})),
?cfgh(M([{max_result_limit, 1000}]),
T(#{<<"max_result_limit">> => 1000})),
?cfgh(M([{async_writer_rdbms_pool, async_pool}]),
T(#{<<"async_writer_rdbms_pool">> => <<"async_pool">>})),
?cfgh(M([{db_jid_format, mam_jid_rfc}]),
T(#{<<"db_jid_format">> => <<"mam_jid_rfc">>})),
?cfgh(M([{db_message_format, mam_message_xml}]),
Expand All @@ -2055,37 +2045,36 @@ test_mod_mam_meta(T, M) ->
T(#{<<"extra_fin_element">> => <<"mod_mam_utils">>})),
?cfgh(M([{extra_lookup_params, mod_mam_utils}]),
T(#{<<"extra_lookup_params">> => <<"mod_mam_utils">>})),
?cfgh(M([{cache, [{module, internal}]}]),
T(#{<<"cache">> => #{<<"module">> => <<"internal">>}})),
?cfgh(M([{cache, [{time_to_live, 8600}]}]),
T(#{<<"cache">> => #{<<"time_to_live">> => 8600}})),
?cfgh(M([{cache, [{time_to_live, infinity}]}]),
T(#{<<"cache">> => #{<<"time_to_live">> => <<"infinity">>}})),
?cfgh(M([{cache, [{number_of_segments, 10}]}]),
T(#{<<"cache">> => #{<<"number_of_segments">> => 10}})),
?cfgh(M([{cache, [{strategy, fifo}]}]),
T(#{<<"cache">> => #{<<"strategy">> => <<"fifo">>}})),
?errh(T(#{<<"backend">> => <<"notepad">>})),
?errh(T(#{<<"no_stanzaid_element">> => <<"true">>})),
?errh(T(#{<<"is_archivable_message">> => <<"mod_mam_fake">>})),
?errh(T(#{<<"archive_chat_markers">> => <<"maybe">>})),
?errh(T(#{<<"message_retraction">> => 1})),
?errh(T(#{<<"cache_users">> => []})),
?errh(T(#{<<"rdbms_message_format">> => <<"complex">>})),
?errh(T(#{<<"async_writer">> => #{}})),
?errh(T(#{<<"flush_interval">> => -1})),
?errh(T(#{<<"max_batch_size">> => -1})),
?errh(T(#{<<"pool_size">> => -1})),
?errh(T(#{<<"user_prefs_store">> => <<"textfile">>})),
?errh(T(#{<<"full_text_search">> => <<"disabled">>})),
?errh(T(#{<<"default_result_limit">> => -1})),
?errh(T(#{<<"max_result_limit">> => -2})),
?errh(T(#{<<"async_writer_rdbms_pool">> => <<>>})),
?errh(T(#{<<"db_jid_format">> => <<"not_a_module">>})),
?errh(T(#{<<"db_message_format">> => <<"not_a_module">>})),
?errh(T(#{<<"simple">> => <<"yes">>})),
?errh(T(#{<<"extra_fin_element">> => <<"bad_module">>})),
?errh(T(#{<<"extra_lookup_params">> => <<"bad_module">>})),
?errh(T(#{<<"extra_lookup_params">> => <<"bad_module">>})).

test_cache_config(T, M) ->
?cfgh(M([{cache_users, false}]),
T(#{<<"cache_users">> => false})),
?cfgh(M([{cache, [{module, internal}]}]),
T(#{<<"cache">> => #{<<"module">> => <<"internal">>}})),
?cfgh(M([{cache, [{time_to_live, 8600}]}]),
T(#{<<"cache">> => #{<<"time_to_live">> => 8600}})),
?cfgh(M([{cache, [{time_to_live, infinity}]}]),
T(#{<<"cache">> => #{<<"time_to_live">> => <<"infinity">>}})),
?cfgh(M([{cache, [{number_of_segments, 10}]}]),
T(#{<<"cache">> => #{<<"number_of_segments">> => 10}})),
?cfgh(M([{cache, [{strategy, fifo}]}]),
T(#{<<"cache">> => #{<<"strategy">> => <<"fifo">>}})),
?errh(T(#{<<"cache_users">> => []})),
?errh(T(#{<<"cache">> => #{<<"module">> => <<"mod_wrong_cache">>}})),
?errh(T(#{<<"cache">> => #{<<"module">> => <<"mod_cache_users">>,
<<"time_to_live">> => 8600}})),
Expand All @@ -2094,6 +2083,20 @@ test_mod_mam_meta(T, M) ->
?errh(T(#{<<"cache">> => #{<<"number_of_segments">> => 0}})),
?errh(T(#{<<"cache">> => #{<<"number_of_segments">> => <<"infinity">>}})).

test_async_worker(T, M) ->
?cfgh(M([{async_writer, [{flush_interval, 1500}]}]),
T(#{<<"async_writer">> => #{<<"flush_interval">> => 1500}})),
?cfgh(M([{async_writer, [{batch_size, 1500}]}]),
T(#{<<"async_writer">> => #{<<"batch_size">> => 1500}})),
?cfgh(M([{async_writer, [{pool_size, 1500}]}]),
T(#{<<"async_writer">> => #{<<"pool_size">> => 1500}})),
?cfgh(M([{async_writer, [{enabled, false}]}]),
T(#{<<"async_writer">> => #{<<"enabled">> => false}})),
?errh(T(#{<<"async_writer">> => #{<<"flush_interval">> => -1}})),
?errh(T(#{<<"async_writer">> => #{<<"batch_size">> => -1}})),
?errh(T(#{<<"async_writer">> => #{<<"pool_size">> => -1}})),
?errh(T(#{<<"async_writer">> => #{<<"enabled">> => <<"wrong">>}})).

mod_muc(_Config) ->
T = fun(Opts) -> #{<<"modules">> => #{<<"mod_muc">> => Opts}} end,
M = fun(Cfg) -> modopts(mod_muc, Cfg) end,
Expand Down
10 changes: 6 additions & 4 deletions test/config_parser_SUITE_data/modules.options
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{password_strength,32},
{registration_watchers,[<<"JID1">>,<<"JID2">>]},
{welcome_message,{"Subject","Body"}}]},
{mod_mam_rdbms_async_pool_writer,[pm]},
{mod_mam_rdbms_arch_async, [{pm, []}]},
{mod_adhoc,[{iqdisc,one_queue},{report_commands_node,true}]},
{mod_event_pusher_sns,
[{access_key_id,"AKIAIOSFODNN7EXAMPLE"},
Expand Down Expand Up @@ -100,6 +100,7 @@
{mod_mam_mnesia_prefs,[muc]},
{mod_mam_muc,
[{archive_chat_markers,true},
{async_writer,[{enabled,false}]},
{full_text_search,true},
{host,{fqdn,<<"muc.example.com">>}},
{is_archivable_message,mod_mam_utils}]},
Expand Down Expand Up @@ -195,7 +196,7 @@
{full_text_search,true},
{is_archivable_message,mod_mam_utils},
{muc,
[{async_writer,false},
[{async_writer, [{enabled,false}]},
{host,{fqdn,<<"muc.example.com">>}},
{rdbms_message_format,simple},
{user_prefs_store,mnesia}]},
Expand Down Expand Up @@ -311,7 +312,7 @@
{password_strength,32},
{registration_watchers,[<<"JID1">>,<<"JID2">>]},
{welcome_message,{"Subject","Body"}}]},
{mod_mam_rdbms_async_pool_writer,[pm]},
{mod_mam_rdbms_arch_async, [{pm, []}]},
{mod_adhoc,[{iqdisc,one_queue},{report_commands_node,true}]},
{mod_event_pusher_sns,
[{access_key_id,"AKIAIOSFODNN7EXAMPLE"},
Expand Down Expand Up @@ -364,6 +365,7 @@
{mod_mam_mnesia_prefs,[muc]},
{mod_mam_muc,
[{archive_chat_markers,true},
{async_writer,[{enabled,false}]},
{full_text_search,true},
{host,{fqdn,<<"muc.example.com">>}},
{is_archivable_message,mod_mam_utils}]},
Expand Down Expand Up @@ -459,7 +461,7 @@
{full_text_search,true},
{is_archivable_message,mod_mam_utils},
{muc,
[{async_writer,false},
[{async_writer, [{enabled,false}]},
{host,{fqdn,<<"muc.example.com">>}},
{rdbms_message_format,simple},
{user_prefs_store,mnesia}]},
Expand Down
2 changes: 1 addition & 1 deletion test/config_parser_SUITE_data/modules.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
pm.full_text_search = false
muc.host = "muc.example.com"
muc.rdbms_message_format = "simple"
muc.async_writer = false
muc.async_writer.enabled = false
muc.user_prefs_store = "mnesia"

[modules.mod_muc]
Expand Down
23 changes: 11 additions & 12 deletions test/mod_mam_meta_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ handles_only_muc(_Config) ->


disables_sync_writer_on_async_writer(_Config) ->
Deps = deps([{pm, [async_writer]}]),
Deps = deps([{pm, [{async_writer, []}]}]),
{_, Args, _} = lists:keyfind(mod_mam_rdbms_arch, 1, Deps),
?assert(lists:member(no_writer, Args)).


disables_sync_muc_writer_on_async_writer(_Config) ->
Deps = deps([{muc, [async_writer]}]),
Deps = deps([{muc, [{async_writer, []}]}]),
{_, Args, _} = lists:keyfind(mod_mam_muc_rdbms_arch, 1, Deps),
?assert(lists:member(no_writer, Args)).

Expand All @@ -66,7 +66,7 @@ produces_valid_configurations(_Config) ->
{backend, rdbms},
cache_users,

{pm, [{user_prefs_store, rdbms}, archive_groupchats, {async_writer, false}]},
{pm, [{user_prefs_store, rdbms}, archive_groupchats, {async_writer, [{enabled, false}]}]},
{muc, [
{host, <<"host">>},
{rdbms_message_format, simple},
Expand All @@ -84,12 +84,11 @@ produces_valid_configurations(_Config) ->
check_has_args(mod_mam_cache_user, [pm, muc], Deps),
check_has_args(mod_mam_mnesia_prefs, [muc], Deps),
check_has_args(mod_mam_rdbms_prefs, [pm], Deps),
check_has_args(mod_mam_muc_rdbms_async_pool_writer, [], Deps),
check_has_args(mod_mam_rdbms_arch_async, [{muc, []}], Deps),

check_has_no_args(mod_mam_rdbms_arch, [muc, no_writer | ExpandedSimpleOpts], Deps),
check_has_no_args(mod_mam_mnesia_prefs, [pm], Deps),
check_has_no_args(mod_mam_rdbms_prefs, [muc], Deps),
?assertNot(lists:keymember(mod_mam_rdbms_async_pool_writer, 1, Deps)).
check_has_no_args(mod_mam_rdbms_prefs, [muc], Deps).


handles_riak_config(_Config) ->
Expand Down Expand Up @@ -127,7 +126,7 @@ handles_cassandra_config(_Config) ->
example_muc_only_no_pref_good_performance(_Config) ->
Deps = deps([
cache_users,
async_writer,
{async_writer, []},
{muc, [{host, "muc.@HOST@"}]}
]),

Expand All @@ -137,16 +136,16 @@ example_muc_only_no_pref_good_performance(_Config) ->
%% 'muc' argument is ignored by the module
{mod_mam_muc_rdbms_arch, [muc, no_writer]},
%% 'muc' argument is ignored by the module
{mod_mam_muc_rdbms_async_pool_writer, [muc]},
{mod_mam_muc, [{host, "muc.@HOST@"}]}
{mod_mam_rdbms_arch_async, [{muc, []}]},
{mod_mam_muc, [{async_writer, []}, {host, "muc.@HOST@"}]}
], Deps).


example_pm_only_good_performance(_Config) ->
Deps = deps([
{pm, []},
cache_users,
async_writer,
{async_writer, []},
{user_prefs_store, mnesia}
]),

Expand All @@ -155,8 +154,8 @@ example_pm_only_good_performance(_Config) ->
{mod_mam_cache_user, [pm]},
{mod_mam_mnesia_prefs, [pm]},
{mod_mam_rdbms_arch, [pm, no_writer]},
{mod_mam_rdbms_async_pool_writer, [pm]},
{mod_mam, []}
{mod_mam_rdbms_arch_async, [{pm, []}]},
{mod_mam, [{async_writer, []}]}
], Deps).

%% Helpers
Expand Down

0 comments on commit c909eac

Please sign in to comment.