test(limiter): fix test errors and make spellcheck happy
This commit is contained in:
parent
2a54d93c7e
commit
02f8d073f8
|
@ -437,7 +437,7 @@ importance_of_type(_) ->
|
||||||
|
|
||||||
alias_of_type(messages) ->
|
alias_of_type(messages) ->
|
||||||
[message_in];
|
[message_in];
|
||||||
alias_of_type(bytess) ->
|
alias_of_type(bytes) ->
|
||||||
[bytes_in];
|
[bytes_in];
|
||||||
alias_of_type(_) ->
|
alias_of_type(_) ->
|
||||||
[].
|
[].
|
||||||
|
|
|
@ -162,8 +162,7 @@ limiter_conf() ->
|
||||||
Make = fun() ->
|
Make = fun() ->
|
||||||
#{
|
#{
|
||||||
burst => 0,
|
burst => 0,
|
||||||
rate => infinity,
|
rate => infinity
|
||||||
capacity => infinity
|
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
@ -172,7 +171,7 @@ limiter_conf() ->
|
||||||
Acc#{Name => Make()}
|
Acc#{Name => Make()}
|
||||||
end,
|
end,
|
||||||
#{},
|
#{},
|
||||||
[bytes_in, message_in, message_routing, connection, internal]
|
[bytes, messages, message_routing, connection, internal]
|
||||||
).
|
).
|
||||||
|
|
||||||
stats_conf() ->
|
stats_conf() ->
|
||||||
|
@ -1258,7 +1257,7 @@ limiter_cfg() ->
|
||||||
Client = #{
|
Client = #{
|
||||||
rate => 5,
|
rate => 5,
|
||||||
initial => 0,
|
initial => 0,
|
||||||
capacity => 5,
|
burst => 0,
|
||||||
low_watermark => 1,
|
low_watermark => 1,
|
||||||
divisible => false,
|
divisible => false,
|
||||||
max_retry_time => timer:seconds(5),
|
max_retry_time => timer:seconds(5),
|
||||||
|
@ -1270,7 +1269,7 @@ limiter_cfg() ->
|
||||||
}.
|
}.
|
||||||
|
|
||||||
bucket_cfg() ->
|
bucket_cfg() ->
|
||||||
#{rate => 10, initial => 0, capacity => 10}.
|
#{rate => 10, initial => 0, burst => 0}.
|
||||||
|
|
||||||
add_bucket() ->
|
add_bucket() ->
|
||||||
emqx_limiter_server:add_bucket(?MODULE, message_routing, bucket_cfg()).
|
emqx_limiter_server:add_bucket(?MODULE, message_routing, bucket_cfg()).
|
||||||
|
|
|
@ -427,7 +427,7 @@ t_ensure_rate_limit(_) ->
|
||||||
fun(_, Client) -> {pause, 3000, undefined, Client} end
|
fun(_, Client) -> {pause, 3000, undefined, Client} end
|
||||||
),
|
),
|
||||||
{ok, State2} = emqx_connection:check_limiter(
|
{ok, State2} = emqx_connection:check_limiter(
|
||||||
[{1000, bytes_in}],
|
[{1000, bytes}],
|
||||||
[],
|
[],
|
||||||
WhenOk,
|
WhenOk,
|
||||||
[],
|
[],
|
||||||
|
@ -703,31 +703,29 @@ handle_call(Pid, Call, St) -> emqx_connection:handle_call(Pid, Call, St).
|
||||||
-define(LIMITER_ID, 'tcp:default').
|
-define(LIMITER_ID, 'tcp:default').
|
||||||
|
|
||||||
init_limiter() ->
|
init_limiter() ->
|
||||||
emqx_limiter_container:get_limiter_by_types(?LIMITER_ID, [bytes_in, message_in], limiter_cfg()).
|
emqx_limiter_container:get_limiter_by_types(?LIMITER_ID, [bytes, messages], limiter_cfg()).
|
||||||
|
|
||||||
limiter_cfg() ->
|
limiter_cfg() ->
|
||||||
Infinity = emqx_limiter_schema:infinity_value(),
|
|
||||||
Cfg = bucket_cfg(),
|
Cfg = bucket_cfg(),
|
||||||
Client = #{
|
Client = #{
|
||||||
rate => Infinity,
|
rate => infinity,
|
||||||
initial => 0,
|
initial => 0,
|
||||||
capacity => Infinity,
|
burst => 0,
|
||||||
low_watermark => 1,
|
low_watermark => 1,
|
||||||
divisible => false,
|
divisible => false,
|
||||||
max_retry_time => timer:seconds(5),
|
max_retry_time => timer:seconds(5),
|
||||||
failure_strategy => force
|
failure_strategy => force
|
||||||
},
|
},
|
||||||
#{bytes_in => Cfg, message_in => Cfg, client => #{bytes_in => Client, message_in => Client}}.
|
#{bytes => Cfg, messages => Cfg, client => #{bytes => Client, messages => Client}}.
|
||||||
|
|
||||||
bucket_cfg() ->
|
bucket_cfg() ->
|
||||||
Infinity = emqx_limiter_schema:infinity_value(),
|
#{rate => infinity, initial => 0, burst => 0}.
|
||||||
#{rate => Infinity, initial => 0, capacity => Infinity}.
|
|
||||||
|
|
||||||
add_bucket() ->
|
add_bucket() ->
|
||||||
Cfg = bucket_cfg(),
|
Cfg = bucket_cfg(),
|
||||||
emqx_limiter_server:add_bucket(?LIMITER_ID, bytes_in, Cfg),
|
emqx_limiter_server:add_bucket(?LIMITER_ID, bytes, Cfg),
|
||||||
emqx_limiter_server:add_bucket(?LIMITER_ID, message_in, Cfg).
|
emqx_limiter_server:add_bucket(?LIMITER_ID, messages, Cfg).
|
||||||
|
|
||||||
del_bucket() ->
|
del_bucket() ->
|
||||||
emqx_limiter_server:del_bucket(?LIMITER_ID, bytes_in),
|
emqx_limiter_server:del_bucket(?LIMITER_ID, bytes),
|
||||||
emqx_limiter_server:del_bucket(?LIMITER_ID, message_in).
|
emqx_limiter_server:del_bucket(?LIMITER_ID, messages).
|
||||||
|
|
|
@ -509,16 +509,16 @@ t_handle_timeout_emit_stats(_) ->
|
||||||
t_ensure_rate_limit(_) ->
|
t_ensure_rate_limit(_) ->
|
||||||
{ok, Rate} = emqx_limiter_schema:to_rate("50MB"),
|
{ok, Rate} = emqx_limiter_schema:to_rate("50MB"),
|
||||||
Limiter = init_limiter(#{
|
Limiter = init_limiter(#{
|
||||||
bytes_in => bucket_cfg(),
|
bytes => bucket_cfg(),
|
||||||
message_in => bucket_cfg(),
|
messages => bucket_cfg(),
|
||||||
client => #{bytes_in => client_cfg(Rate)}
|
client => #{bytes => client_cfg(Rate)}
|
||||||
}),
|
}),
|
||||||
St = st(#{limiter => Limiter}),
|
St = st(#{limiter => Limiter}),
|
||||||
|
|
||||||
%% must bigger than value in emqx_ratelimit_SUITE
|
%% must bigger than value in emqx_ratelimit_SUITE
|
||||||
{ok, Need} = emqx_limiter_schema:to_capacity("1GB"),
|
{ok, Need} = emqx_limiter_schema:to_capacity("1GB"),
|
||||||
St1 = ?ws_conn:check_limiter(
|
St1 = ?ws_conn:check_limiter(
|
||||||
[{Need, bytes_in}],
|
[{Need, bytes}],
|
||||||
[],
|
[],
|
||||||
fun(_, _, S) -> S end,
|
fun(_, _, S) -> S end,
|
||||||
[],
|
[],
|
||||||
|
@ -699,23 +699,21 @@ init_limiter() ->
|
||||||
init_limiter(limiter_cfg()).
|
init_limiter(limiter_cfg()).
|
||||||
|
|
||||||
init_limiter(LimiterCfg) ->
|
init_limiter(LimiterCfg) ->
|
||||||
emqx_limiter_container:get_limiter_by_types(?LIMITER_ID, [bytes_in, message_in], LimiterCfg).
|
emqx_limiter_container:get_limiter_by_types(?LIMITER_ID, [bytes, messages], LimiterCfg).
|
||||||
|
|
||||||
limiter_cfg() ->
|
limiter_cfg() ->
|
||||||
Cfg = bucket_cfg(),
|
Cfg = bucket_cfg(),
|
||||||
Client = client_cfg(),
|
Client = client_cfg(),
|
||||||
#{bytes_in => Cfg, message_in => Cfg, client => #{bytes_in => Client, message_in => Client}}.
|
#{bytes => Cfg, messages => Cfg, client => #{bytes => Client, messages => Client}}.
|
||||||
|
|
||||||
client_cfg() ->
|
client_cfg() ->
|
||||||
Infinity = emqx_limiter_schema:infinity_value(),
|
client_cfg(infinity).
|
||||||
client_cfg(Infinity).
|
|
||||||
|
|
||||||
client_cfg(Rate) ->
|
client_cfg(Rate) ->
|
||||||
Infinity = emqx_limiter_schema:infinity_value(),
|
|
||||||
#{
|
#{
|
||||||
rate => Rate,
|
rate => Rate,
|
||||||
initial => 0,
|
initial => 0,
|
||||||
capacity => Infinity,
|
burst => 0,
|
||||||
low_watermark => 1,
|
low_watermark => 1,
|
||||||
divisible => false,
|
divisible => false,
|
||||||
max_retry_time => timer:seconds(5),
|
max_retry_time => timer:seconds(5),
|
||||||
|
@ -723,14 +721,13 @@ client_cfg(Rate) ->
|
||||||
}.
|
}.
|
||||||
|
|
||||||
bucket_cfg() ->
|
bucket_cfg() ->
|
||||||
Infinity = emqx_limiter_schema:infinity_value(),
|
#{rate => infinity, initial => 0, burst => 0}.
|
||||||
#{rate => Infinity, initial => 0, capacity => Infinity}.
|
|
||||||
|
|
||||||
add_bucket() ->
|
add_bucket() ->
|
||||||
Cfg = bucket_cfg(),
|
Cfg = bucket_cfg(),
|
||||||
emqx_limiter_server:add_bucket(?LIMITER_ID, bytes_in, Cfg),
|
emqx_limiter_server:add_bucket(?LIMITER_ID, bytes, Cfg),
|
||||||
emqx_limiter_server:add_bucket(?LIMITER_ID, message_in, Cfg).
|
emqx_limiter_server:add_bucket(?LIMITER_ID, messages, Cfg).
|
||||||
|
|
||||||
del_bucket() ->
|
del_bucket() ->
|
||||||
emqx_limiter_server:del_bucket(?LIMITER_ID, bytes_in),
|
emqx_limiter_server:del_bucket(?LIMITER_ID, bytes),
|
||||||
emqx_limiter_server:del_bucket(?LIMITER_ID, message_in).
|
emqx_limiter_server:del_bucket(?LIMITER_ID, messages).
|
||||||
|
|
|
@ -758,23 +758,22 @@ with_conf(ConfMod, Case) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
make_limiter_cfg(Rate) ->
|
make_limiter_cfg(Rate) ->
|
||||||
Infinity = emqx_limiter_schema:infinity_value(),
|
|
||||||
Client = #{
|
Client = #{
|
||||||
rate => Rate,
|
rate => Rate,
|
||||||
initial => 0,
|
initial => 0,
|
||||||
capacity => Infinity,
|
burst => 0,
|
||||||
low_watermark => 1,
|
low_watermark => 1,
|
||||||
divisible => false,
|
divisible => false,
|
||||||
max_retry_time => timer:seconds(5),
|
max_retry_time => timer:seconds(5),
|
||||||
failure_strategy => force
|
failure_strategy => force
|
||||||
},
|
},
|
||||||
#{client => Client, rate => Infinity, initial => 0, capacity => Infinity}.
|
#{client => Client, rate => Rate, initial => 0, burst => 0}.
|
||||||
|
|
||||||
make_limiter_json(Rate) ->
|
make_limiter_json(Rate) ->
|
||||||
Client = #{
|
Client = #{
|
||||||
<<"rate">> => Rate,
|
<<"rate">> => Rate,
|
||||||
<<"initial">> => 0,
|
<<"initial">> => 0,
|
||||||
<<"capacity">> => <<"infinity">>,
|
<<"burst">> => <<"0">>,
|
||||||
<<"low_watermark">> => 0,
|
<<"low_watermark">> => 0,
|
||||||
<<"divisible">> => <<"false">>,
|
<<"divisible">> => <<"false">>,
|
||||||
<<"max_retry_time">> => <<"5s">>,
|
<<"max_retry_time">> => <<"5s">>,
|
||||||
|
@ -784,5 +783,5 @@ make_limiter_json(Rate) ->
|
||||||
<<"client">> => Client,
|
<<"client">> => Client,
|
||||||
<<"rate">> => <<"infinity">>,
|
<<"rate">> => <<"infinity">>,
|
||||||
<<"initial">> => 0,
|
<<"initial">> => 0,
|
||||||
<<"capacity">> => <<"infinity">>
|
<<"burst">> => <<"0">>
|
||||||
}.
|
}.
|
||||||
|
|
|
@ -132,7 +132,7 @@ Once the limit is reached, new connections will be refused"""
|
||||||
|
|
||||||
messages {
|
messages {
|
||||||
desc {
|
desc {
|
||||||
en: """The messages limiter.
|
en: """The `messages` limiter.
|
||||||
This is used to limit the inbound message numbers for this EMQX node
|
This is used to limit the inbound message numbers for this EMQX node
|
||||||
Once the limit is reached, the restricted client will be slow down even be hung for a while."""
|
Once the limit is reached, the restricted client will be slow down even be hung for a while."""
|
||||||
zh: """流入速率控制器。
|
zh: """流入速率控制器。
|
||||||
|
@ -146,7 +146,7 @@ Once the limit is reached, the restricted client will be slow down even be hung
|
||||||
|
|
||||||
bytes {
|
bytes {
|
||||||
desc {
|
desc {
|
||||||
en: """The bytes limiter.
|
en: """The `bytes` limiter.
|
||||||
This is used to limit the inbound bytes rate for this EMQX node.
|
This is used to limit the inbound bytes rate for this EMQX node.
|
||||||
Once the limit is reached, the restricted client will be slow down even be hung for a while."""
|
Once the limit is reached, the restricted client will be slow down even be hung for a while."""
|
||||||
zh: """流入字节率控制器。
|
zh: """流入字节率控制器。
|
||||||
|
|
Loading…
Reference in New Issue