diff --git a/big_tests/tests/xep_0352_csi_SUITE.erl b/big_tests/tests/xep_0352_csi_SUITE.erl index 3b0381422e..48b931eb36 100644 --- a/big_tests/tests/xep_0352_csi_SUITE.erl +++ b/big_tests/tests/xep_0352_csi_SUITE.erl @@ -6,6 +6,7 @@ -compile([export_all, nowarn_export_all]). -import(domain_helper, [host_type/0]). +-import(config_parser_helper, [default_mod_config/1, mod_config/2]). -define(CSI_BUFFER_MAX, 10). @@ -35,8 +36,8 @@ suite() -> init_per_suite(Config) -> NewConfig = dynamic_modules:save_modules(host_type(), Config), dynamic_modules:ensure_modules( - host_type(), [{mod_offline, config_parser_helper:mod_config(mod_offline, #{})}, - {mod_csi, [{buffer_max, ?CSI_BUFFER_MAX}]}]), + host_type(), [{mod_offline, default_mod_config(mod_offline)}, + {mod_csi, mod_config(mod_csi, #{buffer_max => ?CSI_BUFFER_MAX})}]), [{escalus_user_db, {module, escalus_ejabberd}} | escalus:init_per_suite(NewConfig)]. end_per_suite(Config) -> diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index 5ffc727eed..291cbca3bf 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -2740,8 +2740,7 @@ maybe_csi_inactive_optimisation(Acc, {From,To,El}, #state{csi_buffer = Buffer} = {ok, Acc, NewState}. flush_or_buffer_packets(State) -> - MaxBuffSize = gen_mod:get_module_opt(State#state.host_type, mod_csi, - buffer_max, 20), + MaxBuffSize = gen_mod:get_module_opt(State#state.host_type, mod_csi, buffer_max), case length(State#state.csi_buffer) > MaxBuffSize of true -> flush_csi_buffer(State); diff --git a/src/mod_csi.erl b/src/mod_csi.erl index 59a8b1fe48..f305d6fe23 100644 --- a/src/mod_csi.erl +++ b/src/mod_csi.erl @@ -51,8 +51,10 @@ ensure_metrics(HostType) -> config_spec() -> #section{ items = #{<<"buffer_max">> => #option{type = int_or_infinity, - validate = non_negative}} - }. + validate = non_negative}}, + format_items = map, + defaults = #{<<"buffer_max">> => 20} + }. -spec supported_features() -> [atom()]. supported_features() -> diff --git a/test/common/config_parser_helper.erl b/test/common/config_parser_helper.erl index 89270730f1..2b214e00f2 100644 --- a/test/common/config_parser_helper.erl +++ b/test/common/config_parser_helper.erl @@ -538,7 +538,7 @@ all_modules() -> port => 2222, transport => <<"tcp">>, type => stun, username => <<"username">>}, #{host => <<"192.168.0.1">>, type => turn}]}, - mod_csi => [{buffer_max, 40}], + mod_csi => mod_config(mod_csi, #{buffer_max => 40}), mod_muc_log => mod_config(mod_muc_log, #{access_log => muc, @@ -855,6 +855,8 @@ default_mod_config(mod_cache_users) -> default_mod_config(mod_caps) -> #{cache_size => 1000, cache_life_time => timer:hours(24) div 1000}; +default_mod_config(mod_csi) -> + #{buffer_max => 20}; default_mod_config(mod_disco) -> #{extra_domains => [], server_info => [], users_can_see_hidden_services => true, iqdisc => one_queue}; diff --git a/test/config_parser_SUITE.erl b/test/config_parser_SUITE.erl index 96fae27c88..62a4e4d0e8 100644 --- a/test/config_parser_SUITE.erl +++ b/test/config_parser_SUITE.erl @@ -1656,10 +1656,11 @@ mod_carboncopy(_Config) -> check_iqdisc(mod_carboncopy). mod_csi(_Config) -> + check_module_defaults(mod_csi), T = fun(K, V) -> #{<<"modules">> => #{<<"mod_csi">> => #{K => V}}} end, - M = fun(K, V) -> modopts(mod_csi, [{K, V}]) end, - ?cfgh(M(buffer_max, 10), T(<<"buffer_max">>, 10)), - ?cfgh(M(buffer_max, infinity), T(<<"buffer_max">>, <<"infinity">>)), + P = [modules, mod_csi], + ?cfgh(P ++ [buffer_max], 10, T(<<"buffer_max">>, 10)), + ?cfgh(P ++ [buffer_max], infinity, T(<<"buffer_max">>, <<"infinity">>)), ?errh(T(<<"buffer_max">>, -1)). mod_disco(_Config) ->