Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put mod_csi option in a map with defaults #3605

Merged
merged 1 commit into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions big_tests/tests/xep_0352_csi_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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) ->
Expand Down
3 changes: 1 addition & 2 deletions src/ejabberd_c2s.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/mod_csi.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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() ->
Expand Down
4 changes: 3 additions & 1 deletion test/common/config_parser_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -856,6 +856,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};
Expand Down
7 changes: 4 additions & 3 deletions test/config_parser_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down