From ae387d1812285895281be699805a020d66f42d36 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Wed, 24 Jan 2024 18:02:47 -0300 Subject: [PATCH] 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. --- apps/emqx/test/emqx_cth_cluster.erl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/emqx/test/emqx_cth_cluster.erl b/apps/emqx/test/emqx_cth_cluster.erl index d53bb1e90..0ac597ff6 100644 --- a/apps/emqx/test/emqx_cth_cluster.erl +++ b/apps/emqx/test/emqx_cth_cluster.erl @@ -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.