Fix the test cases for session, channel and connection modules
This commit is contained in:
parent
8ab682151d
commit
977b551bbf
|
@ -106,9 +106,9 @@
|
||||||
will_timer => will_message
|
will_timer => will_message
|
||||||
}).
|
}).
|
||||||
|
|
||||||
-define(ATTR_KEYS, [conninfo, client, session]).
|
-define(ATTR_KEYS, [conninfo, clientinfo, session]).
|
||||||
|
|
||||||
-define(INFO_KEYS, ?ATTR_KEYS ++ [conninfo, client, session, keepalive,
|
-define(INFO_KEYS, ?ATTR_KEYS ++ [conninfo, clientinfo, session, keepalive,
|
||||||
will_msg, topic_aliases, alias_maximum, gc_state]).
|
will_msg, topic_aliases, alias_maximum, gc_state]).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -125,7 +125,7 @@ info(Keys, Channel) when is_list(Keys) ->
|
||||||
[{Key, info(Key, Channel)} || Key <- Keys];
|
[{Key, info(Key, Channel)} || Key <- Keys];
|
||||||
info(conninfo, #channel{conninfo = ConnInfo}) ->
|
info(conninfo, #channel{conninfo = ConnInfo}) ->
|
||||||
ConnInfo;
|
ConnInfo;
|
||||||
info(client, #channel{clientinfo = ClientInfo}) ->
|
info(clientinfo, #channel{clientinfo = ClientInfo}) ->
|
||||||
ClientInfo;
|
ClientInfo;
|
||||||
info(session, #channel{session = Session}) ->
|
info(session, #channel{session = Session}) ->
|
||||||
maybe_apply(fun emqx_session:info/1, Session);
|
maybe_apply(fun emqx_session:info/1, Session);
|
||||||
|
|
|
@ -139,8 +139,7 @@ stats(#state{transport = Transport,
|
||||||
ConnStats = emqx_pd:get_counters(?CONN_STATS),
|
ConnStats = emqx_pd:get_counters(?CONN_STATS),
|
||||||
ChanStats = emqx_channel:stats(ChanState),
|
ChanStats = emqx_channel:stats(ChanState),
|
||||||
ProcStats = emqx_misc:proc_stats(),
|
ProcStats = emqx_misc:proc_stats(),
|
||||||
[{sock_stats, SockStats}, {conn_stats, ConnStats},
|
lists:append([SockStats, ConnStats, ChanStats, ProcStats]).
|
||||||
{chan_stats, ChanStats}, {proc_stats, ProcStats}].
|
|
||||||
|
|
||||||
%% kick|discard|takeover
|
%% kick|discard|takeover
|
||||||
-spec(call(pid(), Req :: term()) -> Reply :: term()).
|
-spec(call(pid(), Req :: term()) -> Reply :: term()).
|
||||||
|
|
|
@ -128,7 +128,8 @@ proc_stats(Pid) ->
|
||||||
reductions,
|
reductions,
|
||||||
memory]) of
|
memory]) of
|
||||||
undefined -> [];
|
undefined -> [];
|
||||||
ProcStats -> ProcStats
|
[{message_queue_len, Len}|ProcStats] ->
|
||||||
|
[{mailbox_len, Len}|ProcStats]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% @doc Drain delivers from the channel's mailbox.
|
%% @doc Drain delivers from the channel's mailbox.
|
||||||
|
|
|
@ -92,10 +92,11 @@ info(chan_state, #state{chan_state = ChanState}) ->
|
||||||
stats(WsPid) when is_pid(WsPid) ->
|
stats(WsPid) when is_pid(WsPid) ->
|
||||||
call(WsPid, stats);
|
call(WsPid, stats);
|
||||||
stats(#state{chan_state = ChanState}) ->
|
stats(#state{chan_state = ChanState}) ->
|
||||||
[{sock_stats, emqx_pd:get_counters(?SOCK_STATS)},
|
SockStats = emqx_pd:get_counters(?SOCK_STATS),
|
||||||
{conn_stats, emqx_pd:get_counters(?CONN_STATS)},
|
ConnStats = emqx_pd:get_counters(?CONN_STATS),
|
||||||
{chan_stats, emqx_channel:stats(ChanState)},
|
ChanStats = emqx_channel:stats(ChanState),
|
||||||
{proc_stats, emqx_misc:proc_stats()}].
|
ProcStats = emqx_misc:proc_stats(),
|
||||||
|
lists:append([SockStats, ConnStats, ChanStats, ProcStats]).
|
||||||
|
|
||||||
%% kick|discard|takeover
|
%% kick|discard|takeover
|
||||||
-spec(call(pid(), Req :: term()) -> Reply :: term()).
|
-spec(call(pid(), Req :: term()) -> Reply :: term()).
|
||||||
|
|
|
@ -74,7 +74,7 @@ t_handle_connect(_) ->
|
||||||
{ok, ?CONNACK_PACKET(?RC_SUCCESS), Channel1}
|
{ok, ?CONNACK_PACKET(?RC_SUCCESS), Channel1}
|
||||||
= handle_in(?CONNECT_PACKET(ConnPkt), Channel),
|
= handle_in(?CONNECT_PACKET(ConnPkt), Channel),
|
||||||
#{clientid := ClientId, username := Username}
|
#{clientid := ClientId, username := Username}
|
||||||
= emqx_channel:info(client, Channel1),
|
= emqx_channel:info(clientinfo, Channel1),
|
||||||
?assertEqual(<<"clientid">>, ClientId),
|
?assertEqual(<<"clientid">>, ClientId),
|
||||||
?assertEqual(<<"username">>, Username)
|
?assertEqual(<<"username">>, Username)
|
||||||
end).
|
end).
|
||||||
|
|
|
@ -98,7 +98,7 @@ t_cm(_) ->
|
||||||
{ok, C} = emqtt:start_link([{clientid, ClientId}]),
|
{ok, C} = emqtt:start_link([{clientid, ClientId}]),
|
||||||
{ok, _} = emqtt:connect(C),
|
{ok, _} = emqtt:connect(C),
|
||||||
ct:sleep(50),
|
ct:sleep(50),
|
||||||
#{client := #{clientid := ClientId}} = emqx_cm:get_chan_attrs(ClientId),
|
#{clientinfo := #{clientid := ClientId}} = emqx_cm:get_chan_attrs(ClientId),
|
||||||
emqtt:subscribe(C, <<"mytopic">>, 0),
|
emqtt:subscribe(C, <<"mytopic">>, 0),
|
||||||
ct:sleep(1200),
|
ct:sleep(1200),
|
||||||
Stats = emqx_cm:get_chan_stats(ClientId),
|
Stats = emqx_cm:get_chan_stats(ClientId),
|
||||||
|
|
|
@ -87,7 +87,7 @@ t_proc_stats(_) ->
|
||||||
Pid2 = spawn(fun() -> timer:sleep(100) end),
|
Pid2 = spawn(fun() -> timer:sleep(100) end),
|
||||||
Pid2 ! msg,
|
Pid2 ! msg,
|
||||||
timer:sleep(10),
|
timer:sleep(10),
|
||||||
?assertMatch([{message_queue_len, 1}|_], emqx_misc:proc_stats(Pid2)).
|
?assertMatch([{mailbox_len, 1}|_], emqx_misc:proc_stats(Pid2)).
|
||||||
|
|
||||||
t_drain_deliver(_) ->
|
t_drain_deliver(_) ->
|
||||||
self() ! {deliver, t1, m1},
|
self() ! {deliver, t1, m1},
|
||||||
|
|
|
@ -91,7 +91,7 @@ recv_and_check_presence(ClientId, Presence) ->
|
||||||
<<"disconnected">> ->
|
<<"disconnected">> ->
|
||||||
?assertMatch(#{clientid := <<"clientid">>,
|
?assertMatch(#{clientid := <<"clientid">>,
|
||||||
username := <<"username">>,
|
username := <<"username">>,
|
||||||
reason := <<"closed">>}, emqx_json:decode(Payload, [{labels, atom}, return_maps]))
|
reason := <<"normal">>}, emqx_json:decode(Payload, [{labels, atom}, return_maps]))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% Test case for emqx_mod_subscription
|
%% Test case for emqx_mod_subscription
|
||||||
|
|
|
@ -170,17 +170,17 @@ deliver_args() ->
|
||||||
|
|
||||||
info_args() ->
|
info_args() ->
|
||||||
oneof([subscriptions,
|
oneof([subscriptions,
|
||||||
max_subscriptions,
|
subscriptions_max,
|
||||||
upgrade_qos,
|
upgrade_qos,
|
||||||
inflight,
|
inflight,
|
||||||
max_inflight,
|
inflight_max,
|
||||||
retry_interval,
|
retry_interval,
|
||||||
mqueue_len,
|
mqueue_len,
|
||||||
max_mqueue,
|
mqueue_max,
|
||||||
mqueue_dropped,
|
mqueue_dropped,
|
||||||
next_pkt_id,
|
next_pkt_id,
|
||||||
awaiting_rel,
|
awaiting_rel,
|
||||||
max_awaiting_rel,
|
awaiting_rel_max,
|
||||||
await_rel_timeout,
|
await_rel_timeout,
|
||||||
created_at
|
created_at
|
||||||
]).
|
]).
|
||||||
|
|
Loading…
Reference in New Issue