test(emqx_mgmt): Exempt do_query function from BPAPI static check

This commit is contained in:
k32 2022-01-19 11:20:54 +01:00
parent 97078002f2
commit a469c466a6
2 changed files with 12 additions and 11 deletions

View File

@ -52,6 +52,11 @@
-define(RPC_FUNCTIONS, "emqx_cluster_rpc:multicall/3, emqx_cluster_rpc:multicall/5").
%% List of functions in the RPC backend modules that we can ignore:
-define(IGNORED_RPC_CALLS, "gen_rpc:nodes/0").
%% List of business-layer functions that are exempt from the checks:
-define(EXEMPTIONS, "emqx_mgmt_api:do_query/6" % Reason: legacy code. A fun and a QC query are
% passed in the args, it's futile to try to statically
% check it
).
-define(XREF, myxref).
@ -207,7 +212,7 @@ prepare(#{reldir := RelDir, plt := PLT}) ->
dialyzer_plt:from_file(PLT).
find_remote_calls(_Opts) ->
Query = "XC | (A - [" ?IGNORED_APPS "]:App - [" ?IGNORED_MODULES "] : Mod)
Query = "XC | (A - [" ?IGNORED_APPS "]:App - [" ?IGNORED_MODULES "]:Mod - [" ?EXEMPTIONS "])
|| (([" ?RPC_MODULES "] : Mod + [" ?RPC_FUNCTIONS "]) - " ?IGNORED_RPC_CALLS ")",
{ok, Calls} = xref:q(?XREF, Query),
?INFO("Calls to RPC modules ~p", [Calls]),

View File

@ -197,12 +197,15 @@ do_cluster_query([Node | Tail] = Nodes, Tab, Qs, QueryFun, Continuation,
%% Do Query (or rpc query)
%%--------------------------------------------------------------------
%% @private
%% @private This function is exempt from BPAPI
do_query(Node, Tab, Qs, {M,F}, Continuation, Limit) when Node =:= node() ->
erlang:apply(M, F, [Tab, Qs, Continuation, Limit]);
do_query(Node, Tab, Qs, QueryFun, Continuation, Limit) ->
rpc_call(Node, ?MODULE, do_query,
[Node, Tab, Qs, QueryFun, Continuation, Limit], 50000).
case rpc:call(Node, ?MODULE, do_query,
[Node, Tab, Qs, QueryFun, Continuation, Limit], 50000) of
{badrpc, _} = R -> {error, R};
Ret -> Ret
end.
sub_query_result(Len, Rows, Limit, Results, Meta) ->
{Flag, NMeta} = judge_page_with_counting(Len, Meta),
@ -219,13 +222,6 @@ sub_query_result(Len, Rows, Limit, Results, Meta) ->
end,
{NMeta, NResults}.
%% @private
rpc_call(Node, M, F, A, T) ->
case rpc:call(Node, M, F, A, T) of
{badrpc, _} = R -> {error, R};
Res -> Res
end.
%%--------------------------------------------------------------------
%% Table Select
%%--------------------------------------------------------------------