Fix the test cases for session, channel and connection modules

This commit is contained in:
Feng Lee 2019-09-29 10:53:59 +08:00
parent 8ab682151d
commit 977b551bbf
9 changed files with 19 additions and 18 deletions

View File

@ -106,9 +106,9 @@
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]).
%%--------------------------------------------------------------------
@ -125,7 +125,7 @@ info(Keys, Channel) when is_list(Keys) ->
[{Key, info(Key, Channel)} || Key <- Keys];
info(conninfo, #channel{conninfo = ConnInfo}) ->
ConnInfo;
info(client, #channel{clientinfo = ClientInfo}) ->
info(clientinfo, #channel{clientinfo = ClientInfo}) ->
ClientInfo;
info(session, #channel{session = Session}) ->
maybe_apply(fun emqx_session:info/1, Session);

View File

@ -139,8 +139,7 @@ stats(#state{transport = Transport,
ConnStats = emqx_pd:get_counters(?CONN_STATS),
ChanStats = emqx_channel:stats(ChanState),
ProcStats = emqx_misc:proc_stats(),
[{sock_stats, SockStats}, {conn_stats, ConnStats},
{chan_stats, ChanStats}, {proc_stats, ProcStats}].
lists:append([SockStats, ConnStats, ChanStats, ProcStats]).
%% kick|discard|takeover
-spec(call(pid(), Req :: term()) -> Reply :: term()).

View File

@ -128,7 +128,8 @@ proc_stats(Pid) ->
reductions,
memory]) of
undefined -> [];
ProcStats -> ProcStats
[{message_queue_len, Len}|ProcStats] ->
[{mailbox_len, Len}|ProcStats]
end.
%% @doc Drain delivers from the channel's mailbox.

View File

@ -92,10 +92,11 @@ info(chan_state, #state{chan_state = ChanState}) ->
stats(WsPid) when is_pid(WsPid) ->
call(WsPid, stats);
stats(#state{chan_state = ChanState}) ->
[{sock_stats, emqx_pd:get_counters(?SOCK_STATS)},
{conn_stats, emqx_pd:get_counters(?CONN_STATS)},
{chan_stats, emqx_channel:stats(ChanState)},
{proc_stats, emqx_misc:proc_stats()}].
SockStats = emqx_pd:get_counters(?SOCK_STATS),
ConnStats = emqx_pd:get_counters(?CONN_STATS),
ChanStats = emqx_channel:stats(ChanState),
ProcStats = emqx_misc:proc_stats(),
lists:append([SockStats, ConnStats, ChanStats, ProcStats]).
%% kick|discard|takeover
-spec(call(pid(), Req :: term()) -> Reply :: term()).

View File

@ -74,7 +74,7 @@ t_handle_connect(_) ->
{ok, ?CONNACK_PACKET(?RC_SUCCESS), Channel1}
= handle_in(?CONNECT_PACKET(ConnPkt), Channel),
#{clientid := ClientId, username := Username}
= emqx_channel:info(client, Channel1),
= emqx_channel:info(clientinfo, Channel1),
?assertEqual(<<"clientid">>, ClientId),
?assertEqual(<<"username">>, Username)
end).

View File

@ -98,7 +98,7 @@ t_cm(_) ->
{ok, C} = emqtt:start_link([{clientid, ClientId}]),
{ok, _} = emqtt:connect(C),
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),
ct:sleep(1200),
Stats = emqx_cm:get_chan_stats(ClientId),

View File

@ -87,7 +87,7 @@ t_proc_stats(_) ->
Pid2 = spawn(fun() -> timer:sleep(100) end),
Pid2 ! msg,
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(_) ->
self() ! {deliver, t1, m1},

View File

@ -91,7 +91,7 @@ recv_and_check_presence(ClientId, Presence) ->
<<"disconnected">> ->
?assertMatch(#{clientid := <<"clientid">>,
username := <<"username">>,
reason := <<"closed">>}, emqx_json:decode(Payload, [{labels, atom}, return_maps]))
reason := <<"normal">>}, emqx_json:decode(Payload, [{labels, atom}, return_maps]))
end.
%% Test case for emqx_mod_subscription

View File

@ -170,17 +170,17 @@ deliver_args() ->
info_args() ->
oneof([subscriptions,
max_subscriptions,
subscriptions_max,
upgrade_qos,
inflight,
max_inflight,
inflight_max,
retry_interval,
mqueue_len,
max_mqueue,
mqueue_max,
mqueue_dropped,
next_pkt_id,
awaiting_rel,
max_awaiting_rel,
awaiting_rel_max,
await_rel_timeout,
created_at
]).