Merge pull request #6238 from zhongwencool/fix-keepalive-ct-failed
fix: keepalive ct failed
This commit is contained in:
commit
f7a55d3f8d
|
@ -74,7 +74,18 @@ check(NewVal, KeepAlive = #keepalive{statval = OldVal,
|
||||||
true -> {error, timeout}
|
true -> {error, timeout}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%% from mqtt-v3.1.1 specific
|
||||||
|
%% A Keep Alive value of zero (0) has the effect of turning off the keep alive mechanism.
|
||||||
|
%% This means that, in this case, the Server is not required
|
||||||
|
%% to disconnect the Client on the grounds of inactivity.
|
||||||
|
%% Note that a Server is permitted to disconnect a Client that it determines
|
||||||
|
%% to be inactive or non-responsive at any time,
|
||||||
|
%% regardless of the Keep Alive value provided by that Client.
|
||||||
|
%% Non normative comment
|
||||||
|
%%The actual value of the Keep Alive is application specific;
|
||||||
|
%% typically this is a few minutes.
|
||||||
|
%% The maximum value is (65535s) 18 hours 12 minutes and 15 seconds.
|
||||||
%% @doc Update keepalive's interval
|
%% @doc Update keepalive's interval
|
||||||
-spec(set(interval, non_neg_integer(), keepalive()) -> keepalive()).
|
-spec(set(interval, non_neg_integer(), keepalive()) -> keepalive()).
|
||||||
set(interval, Interval, KeepAlive) ->
|
set(interval, Interval, KeepAlive) when Interval >= 0 andalso Interval =< 65535000 ->
|
||||||
KeepAlive#keepalive{interval = Interval}.
|
KeepAlive#keepalive{interval = Interval}.
|
||||||
|
|
|
@ -328,8 +328,10 @@ set_ratelimit_policy(ClientId, Policy) ->
|
||||||
set_quota_policy(ClientId, Policy) ->
|
set_quota_policy(ClientId, Policy) ->
|
||||||
call_client(ClientId, {quota, Policy}).
|
call_client(ClientId, {quota, Policy}).
|
||||||
|
|
||||||
set_keepalive(ClientId, Interval) ->
|
set_keepalive(ClientId, Interval)when Interval >= 0 andalso Interval =< 65535 ->
|
||||||
call_client(ClientId, {keepalive, Interval}).
|
call_client(ClientId, {keepalive, Interval});
|
||||||
|
set_keepalive(_ClientId, _Interval) ->
|
||||||
|
{error, <<"mqtt3.1.1 specification: keepalive must between 0~65535">>}.
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
call_client(ClientId, Req) ->
|
call_client(ClientId, Req) ->
|
||||||
|
|
|
@ -457,6 +457,7 @@ keepalive_api() ->
|
||||||
],
|
],
|
||||||
responses => #{
|
responses => #{
|
||||||
<<"404">> => emqx_mgmt_util:error_schema(<<"Client id not found">>),
|
<<"404">> => emqx_mgmt_util:error_schema(<<"Client id not found">>),
|
||||||
|
<<"400">> => emqx_mgmt_util:error_schema(<<"">>, 'PARAMS_ERROR'),
|
||||||
<<"200">> => emqx_mgmt_util:schema(<<"ok">>)}}},
|
<<"200">> => emqx_mgmt_util:schema(<<"ok">>)}}},
|
||||||
{"/clients/:clientid/keepalive", Metadata, set_keepalive}.
|
{"/clients/:clientid/keepalive", Metadata, set_keepalive}.
|
||||||
%%%==============================================================================================
|
%%%==============================================================================================
|
||||||
|
@ -509,7 +510,8 @@ set_keepalive(put, #{bindings := #{clientid := ClientID}, query_string := Query}
|
||||||
Interval = binary_to_integer(Interval0),
|
Interval = binary_to_integer(Interval0),
|
||||||
case emqx_mgmt:set_keepalive(emqx_mgmt_util:urldecode(ClientID), Interval) of
|
case emqx_mgmt:set_keepalive(emqx_mgmt_util:urldecode(ClientID), Interval) of
|
||||||
ok -> {200};
|
ok -> {200};
|
||||||
{error, not_found} ->{404, ?CLIENT_ID_NOT_FOUND}
|
{error, not_found} ->{404, ?CLIENT_ID_NOT_FOUND};
|
||||||
|
{error, Reason} -> {400, #{code => 'PARAMS_ERROR', message => Reason}}
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -175,8 +175,7 @@ t_keepalive(_Config) ->
|
||||||
{ok, Ok} = emqx_mgmt_api_test_util:request_api(put, Path, Query, AuthHeader, <<"">>),
|
{ok, Ok} = emqx_mgmt_api_test_util:request_api(put, Path, Query, AuthHeader, <<"">>),
|
||||||
?assertEqual("", Ok),
|
?assertEqual("", Ok),
|
||||||
[Pid] = emqx_cm:lookup_channels(list_to_binary(ClientId)),
|
[Pid] = emqx_cm:lookup_channels(list_to_binary(ClientId)),
|
||||||
State = sys:get_state(Pid),
|
#{conninfo := #{keepalive := Keepalive}} = emqx_connection:info(Pid),
|
||||||
ct:pal("~p~n", [State]),
|
?assertEqual(11, Keepalive),
|
||||||
?assertEqual(11000, element(2, element(5, element(9, State)))),
|
|
||||||
emqtt:disconnect(C1),
|
emqtt:disconnect(C1),
|
||||||
ok.
|
ok.
|
||||||
|
|
Loading…
Reference in New Issue