ci: start/flush cover when using peer

`cover` is not automatically started by `peer`.  Without starting/flushing it, we don't
get coverage data from peer nodes.
This commit is contained in:
Thales Macedo Garitezi 2024-01-24 18:02:47 -03:00
parent c388a5441d
commit ae387d1812
1 changed files with 19 additions and 0 deletions

View File

@ -381,6 +381,7 @@ node_init(Node) ->
_ = share_load_module(Node, cthr),
% Enable snabbkaffe trace forwarding
ok = snabbkaffe:forward_trace(Node),
when_cover_enabled(fun() -> {ok, _} = cover:start([Node]) end),
ok.
%% Returns 'true' if this node should appear in running nodes list.
@ -445,6 +446,7 @@ stop(Nodes) ->
stop_node(Name) ->
Node = node_name(Name),
when_cover_enabled(fun() -> cover:flush([Node]) end),
ok = emqx_cth_peer:stop(Node).
%% Ports
@ -506,3 +508,20 @@ host() ->
format(Format, Args) ->
unicode:characters_to_binary(io_lib:format(Format, Args)).
is_cover_enabled() ->
case os:getenv("ENABLE_COVER_COMPILE") of
"1" -> true;
"true" -> true;
_ -> false
end.
when_cover_enabled(Fun) ->
%% We need to check if cover is enabled to avoid crashes when attempting to start it
%% on the peer.
case is_cover_enabled() of
true ->
Fun();
false ->
ok
end.