Fix lookup_session_pids return data type error

This commit is contained in:
HeeeJianBo 2019-05-22 16:21:32 +08:00 committed by turtleDeng
parent ac0e637a4b
commit 87ffa77ade
2 changed files with 33 additions and 11 deletions

View File

@ -223,7 +223,11 @@ set_session_stats(ClientId, SessPid, Stats) when is_binary(ClientId), is_pid(Ses
lookup_session_pids(ClientId) -> lookup_session_pids(ClientId) ->
case emqx_sm_registry:is_enabled() of case emqx_sm_registry:is_enabled() of
true -> emqx_sm_registry:lookup_session(ClientId); true -> emqx_sm_registry:lookup_session(ClientId);
false -> emqx_tables:lookup_value(?SESSION_TAB, ClientId, []) false ->
case emqx_tables:lookup_value(?SESSION_TAB, ClientId) of
undefined -> [];
SessPid when is_pid(SessPid) -> [SessPid]
end
end. end.
%% @doc Dispatch a message to the session. %% @doc Dispatch a message to the session.

View File

@ -30,23 +30,33 @@
topic_alias_maximum => 0, topic_alias_maximum => 0,
will_msg => undefined}). will_msg => undefined}).
all() -> [{group, sm}]. all() -> [{group, registry}, {group, ets}].
groups() -> groups() ->
[{sm, [non_parallel_tests], Cases =
[ [ t_resume_session,
t_resume_session,
t_discard_session, t_discard_session,
t_register_unregister_session, t_register_unregister_session,
t_get_set_session_attrs, t_get_set_session_attrs,
t_get_set_session_stats, t_get_set_session_stats,
t_lookup_session_pids]}]. t_lookup_session_pids],
[ {registry, [non_parallel_tests], Cases},
{ets, [non_parallel_tests], Cases}].
init_per_suite(Config) -> init_per_suite(Config) ->
emqx_ct_helpers:start_apps([]),
Config. Config.
end_per_suite(_Config) -> end_per_suite(_Config) ->
ok.
init_per_group(registry, Config) ->
emqx_ct_helpers:start_apps([], fun enable_session_registry/1),
Config;
init_per_group(ets, Config) ->
emqx_ct_helpers:start_apps([], fun disable_session_registry/1),
Config.
end_per_group(_, _Config) ->
emqx_ct_helpers:stop_apps([]). emqx_ct_helpers:stop_apps([]).
init_per_testcase(_All, Config) -> init_per_testcase(_All, Config) ->
@ -60,6 +70,14 @@ end_per_testcase(_All, Config) ->
after 500 -> ct:fail({timeout, wait_session_shutdown}) after 500 -> ct:fail({timeout, wait_session_shutdown})
end. end.
enable_session_registry(_) ->
application:set_env(emqx, enable_session_registry, true),
ok.
disable_session_registry(_) ->
application:set_env(emqx, enable_session_registry, false),
ok.
t_resume_session(Config) -> t_resume_session(Config) ->
?assertEqual({ok, ?config(session_pid, Config)}, emqx_sm:resume_session(<<"client">>, ?ATTRS#{conn_pid => self()})). ?assertEqual({ok, ?config(session_pid, Config)}, emqx_sm:resume_session(<<"client">>, ?ATTRS#{conn_pid => self()})).