fix(test): update test cases for emqx_acl_cache_SUITE
This commit is contained in:
parent
fb78e510ca
commit
14af90d0c3
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
-include("emqx.hrl").
|
-include("emqx.hrl").
|
||||||
|
|
||||||
-export([ list_acl_cache/0
|
-export([ list_acl_cache/2
|
||||||
, get_acl_cache/4
|
, get_acl_cache/4
|
||||||
, put_acl_cache/5
|
, put_acl_cache/5
|
||||||
, cleanup_acl_cache/2
|
, cleanup_acl_cache/2
|
||||||
|
@ -62,8 +62,9 @@ get_cache_max_size(Zone, Listener) ->
|
||||||
get_cache_ttl(Zone, Listener) ->
|
get_cache_ttl(Zone, Listener) ->
|
||||||
emqx_config:get_listener_conf(Zone, Listener, [acl, cache, ttl]).
|
emqx_config:get_listener_conf(Zone, Listener, [acl, cache, ttl]).
|
||||||
|
|
||||||
-spec(list_acl_cache() -> [acl_cache_entry()]).
|
-spec(list_acl_cache(atom(), atom()) -> [acl_cache_entry()]).
|
||||||
list_acl_cache() ->
|
list_acl_cache(Zone, Listener) ->
|
||||||
|
cleanup_acl_cache(Zone, Listener),
|
||||||
map_acl_cache(fun(Cache) -> Cache end).
|
map_acl_cache(fun(Cache) -> Cache end).
|
||||||
|
|
||||||
%% We'll cleanup the cache before replacing an expired acl.
|
%% We'll cleanup the cache before replacing an expired acl.
|
||||||
|
|
|
@ -944,8 +944,9 @@ handle_call({takeover, 'end'}, Channel = #channel{session = Session,
|
||||||
AllPendings = lists:append(Delivers, Pendings),
|
AllPendings = lists:append(Delivers, Pendings),
|
||||||
disconnect_and_shutdown(takeovered, AllPendings, Channel);
|
disconnect_and_shutdown(takeovered, AllPendings, Channel);
|
||||||
|
|
||||||
handle_call(list_acl_cache, Channel) ->
|
handle_call(list_acl_cache, #channel{clientinfo = #{zone := Zone, listener := Listener}}
|
||||||
{reply, emqx_acl_cache:list_acl_cache(), Channel};
|
= Channel) ->
|
||||||
|
{reply, emqx_acl_cache:list_acl_cache(Zone, Listener), Channel};
|
||||||
|
|
||||||
handle_call({quota, Policy}, Channel) ->
|
handle_call({quota, Policy}, Channel) ->
|
||||||
Zone = info(zone, Channel),
|
Zone = info(zone, Channel),
|
||||||
|
|
|
@ -26,6 +26,7 @@ all() -> emqx_ct:all(?MODULE).
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
emqx_ct_helpers:boot_modules(all),
|
emqx_ct_helpers:boot_modules(all),
|
||||||
emqx_ct_helpers:start_apps([]),
|
emqx_ct_helpers:start_apps([]),
|
||||||
|
toggle_acl(true),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
|
@ -55,7 +56,6 @@ t_clean_acl_cache(_) ->
|
||||||
?assertEqual(0, length(gen_server:call(ClientPid, list_acl_cache))),
|
?assertEqual(0, length(gen_server:call(ClientPid, list_acl_cache))),
|
||||||
emqtt:stop(Client).
|
emqtt:stop(Client).
|
||||||
|
|
||||||
|
|
||||||
t_drain_acl_cache(_) ->
|
t_drain_acl_cache(_) ->
|
||||||
{ok, Client} = emqtt:start_link([{clientid, <<"emqx_c">>}]),
|
{ok, Client} = emqtt:start_link([{clientid, <<"emqx_c">>}]),
|
||||||
{ok, _} = emqtt:connect(Client),
|
{ok, _} = emqtt:connect(Client),
|
||||||
|
@ -79,70 +79,5 @@ t_drain_acl_cache(_) ->
|
||||||
?assert(length(gen_server:call(ClientPid, list_acl_cache)) > 0),
|
?assert(length(gen_server:call(ClientPid, list_acl_cache)) > 0),
|
||||||
emqtt:stop(Client).
|
emqtt:stop(Client).
|
||||||
|
|
||||||
% optimize??
|
toggle_acl(Bool) when is_boolean(Bool) ->
|
||||||
t_reload_aclfile_and_cleanall(_Config) ->
|
emqx_config:put_listener_conf(default, mqtt_tcp, [acl, enable], Bool).
|
||||||
|
|
||||||
RasieMsg = fun() -> Self = self(), #{puback => fun(Msg) -> Self ! {puback, Msg} end,
|
|
||||||
disconnected => fun(_) -> ok end,
|
|
||||||
publish => fun(_) -> ok end } end,
|
|
||||||
|
|
||||||
{ok, Client} = emqtt:start_link([{clientid, <<"emqx_c">>}, {proto_ver, v5},
|
|
||||||
{msg_handler, RasieMsg()}]),
|
|
||||||
{ok, _} = emqtt:connect(Client),
|
|
||||||
|
|
||||||
{ok, PktId} = emqtt:publish(Client, <<"t1">>, <<"{\"x\":1}">>, qos1),
|
|
||||||
|
|
||||||
%% Success publish to broker
|
|
||||||
receive
|
|
||||||
{puback, #{packet_id := PktId, reason_code := Rc}} ->
|
|
||||||
?assertEqual(16#10, Rc);
|
|
||||||
_ ->
|
|
||||||
?assert(false)
|
|
||||||
end,
|
|
||||||
|
|
||||||
%% Check acl cache list
|
|
||||||
[ClientPid] = emqx_cm:lookup_channels(<<"emqx_c">>),
|
|
||||||
?assert(length(gen_server:call(ClientPid, list_acl_cache)) > 0),
|
|
||||||
emqtt:stop(Client).
|
|
||||||
|
|
||||||
%% @private
|
|
||||||
testdir(DataPath) ->
|
|
||||||
Ls = filename:split(DataPath),
|
|
||||||
filename:join(lists:sublist(Ls, 1, length(Ls) - 1)).
|
|
||||||
|
|
||||||
% t_cache_k(_) ->
|
|
||||||
% error('TODO').
|
|
||||||
|
|
||||||
% t_cache_v(_) ->
|
|
||||||
% error('TODO').
|
|
||||||
|
|
||||||
% t_cleanup_acl_cache(_) ->
|
|
||||||
% error('TODO').
|
|
||||||
|
|
||||||
% t_get_oldest_key(_) ->
|
|
||||||
% error('TODO').
|
|
||||||
|
|
||||||
% t_get_newest_key(_) ->
|
|
||||||
% error('TODO').
|
|
||||||
|
|
||||||
% t_get_cache_max_size(_) ->
|
|
||||||
% error('TODO').
|
|
||||||
|
|
||||||
% t_get_cache_size(_) ->
|
|
||||||
% error('TODO').
|
|
||||||
|
|
||||||
% t_dump_acl_cache(_) ->
|
|
||||||
% error('TODO').
|
|
||||||
|
|
||||||
% t_empty_acl_cache(_) ->
|
|
||||||
% error('TODO').
|
|
||||||
|
|
||||||
% t_put_acl_cache(_) ->
|
|
||||||
% error('TODO').
|
|
||||||
|
|
||||||
% t_get_acl_cache(_) ->
|
|
||||||
% error('TODO').
|
|
||||||
|
|
||||||
% t_is_enabled(_) ->
|
|
||||||
% error('TODO').
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue