diff --git a/test/emqx_sm_SUITE.erl b/test/emqx_sm_SUITE.erl new file mode 100644 index 000000000..946f85d1b --- /dev/null +++ b/test/emqx_sm_SUITE.erl @@ -0,0 +1,42 @@ +%%-------------------------------------------------------------------- +%% Copyright (c) 2013-2018 EMQ Enterprise, Inc. (http://emqtt.io) +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%%-------------------------------------------------------------------- + +-module(emqx_sm_SUITE). + +-compile(export_all). +-compile(nowarn_export_all). + +-include("emqx.hrl"). + +all() -> [t_open_close_session]. + +t_open_close_session(_) -> + emqx_ct_broker_helpers:run_setup_steps(), + {ok, ClientPid} = emqx_mock_client:start_link(<<"client">>), + Attrs = #{clean_start => true, client_id => <<"client">>, client_pid => ClientPid, zone => internal, username => <<"zhou">>, conn_props => ref}, + {ok, _SPid} = emqx_sm:open_session(Attrs), + [{<<"client">>, SPid}] = emqx_sm:lookup_session(<<"client">>), + SPid = emqx_sm:lookup_session_pid(<<"client">>), + {ok, NewClientPid} = emqx_mock_client:start_link(<<"client">>), + {ok, SPid, true} = emqx_sm:open_session(Attrs#{clean_start => false, client_pid => NewClientPid}), + [{<<"client">>, SPid}] = emqx_sm:lookup_session(<<"client">>), + SAttrs = emqx_sm:get_session_attrs({<<"client">>, SPid}), + <<"client">> = proplists:get_value(client_id, SAttrs), + Session = {<<"client">>, SPid}, + emqx_sm:set_session_stats(Session, {open, true}), + {open, true} = emqx_sm:get_session_stats(Session), + ok = emqx_sm:close_session(SPid), + [] = emqx_sm:lookup_session(<<"client">>). \ No newline at end of file diff --git a/test/emqx_stats_SUITE.erl b/test/emqx_stats_SUITE.erl index b544d6128..c7fc4ecce 100644 --- a/test/emqx_stats_SUITE.erl +++ b/test/emqx_stats_SUITE.erl @@ -25,36 +25,33 @@ all() -> [t_set_get_state, t_update_interval]. t_set_get_state(_) -> {ok, _} = emqx_stats:start_link(), - SetClientsCount = emqx_stats:statsfun('clients/count'), - SetClientsCount(1), - 1 = emqx_stats:getstat('clients/count'), - emqx_stats:setstat('clients/count', 2), - 2 = emqx_stats:getstat('clients/count'), - emqx_stats:setstat('clients/count', 'clients/max', 3), + SetConnsCount = emqx_stats:statsfun('connections/count'), + SetConnsCount(1), + 1 = emqx_stats:getstat('connections/count'), + emqx_stats:setstat('connections/count', 2), + 2 = emqx_stats:getstat('connections/count'), + emqx_stats:setstat('connections/count', 'connections/max', 3), timer:sleep(100), - 3 = emqx_stats:getstat('clients/count'), - 3 = emqx_stats:getstat('clients/max'), - emqx_stats:setstat('clients/count', 'clients/max', 2), + 3 = emqx_stats:getstat('connections/count'), + 3 = emqx_stats:getstat('connections/max'), + emqx_stats:setstat('connections/count', 'connections/max', 2), timer:sleep(100), - 2 = emqx_stats:getstat('clients/count'), - 3 = emqx_stats:getstat('clients/max'), - SetClients = emqx_stats:statsfun('clients/count', 'clients/max'), - SetClients(4), + 2 = emqx_stats:getstat('connections/count'), + 3 = emqx_stats:getstat('connections/max'), + SetConns = emqx_stats:statsfun('connections/count', 'connections/max'), + SetConns(4), timer:sleep(100), - 4 = emqx_stats:getstat('clients/count'), - 4 = emqx_stats:getstat('clients/max'), - Clients = emqx_stats:getstats(), - 4 = proplists:get_value('clients/count', Clients), - 4 = proplists:get_value('clients/max', Clients). + 4 = emqx_stats:getstat('connections/count'), + 4 = emqx_stats:getstat('connections/max'), + Conns = emqx_stats:getstats(), + 4 = proplists:get_value('connections/count', Conns), + 4 = proplists:get_value('connections/max', Conns). t_update_interval(_) -> {ok, _} = emqx_stats:start_link(), ok = emqx_stats:update_interval(cm_stats, fun update_stats/0), - timer:sleep(2000), - 1 = emqx_stats:getstat('clients/count'). + timer:sleep(2500), + 1 = emqx_stats:getstat('connections/count'). update_stats() -> - ClientsCount = emqx_stats:getstat('clients/count'), - ct:log("hello~n"), - % emqx_stats:setstat('clients/count', 'clients/max', ClientsCount + 1). - emqx_stats:setstat('clients/count', 1). \ No newline at end of file + emqx_stats:setstat('connections/count', 1). \ No newline at end of file