Fix coverage

Dependency horus broke coverage on `main` branch.

After this commit, on `main` branch in rabbitmq-server root
directory, both show coverage:

1.
```
make -C deps/rabbitmq_mqtt ct-auth t=[v5,limit]:vhost_queue_limit FULL=1 COVER=1
open deps/rabbitmq_mqtt/logs/index.html
```

2.
```
bazel coverage //deps/rabbitmq_mqtt:auth_SUITE -t- --test_sharding_strategy=disabled --test_env FOCUS="-group [v5,limit] -case vhost_queue_limit"
genhtml --output genhtml "$(bazel info output_path)/_coverage/_coverage_report.dat"
open genhtml/index.html
```
where `genhtml` is
https://github.com/linux-test-project/lcov/blob/master/bin/genhtml

Prior to this commit, coverage was broken with both Bazel and Erlang.mk:

On main - below logs are printed in different outputs:
First:
```
*** CT 2023-11-07 16:40:04.959 *** COVER INFO🔗
Adding nodes to cover test: ['rmq-ct-reader_SUITE-1-21000@localhost']
```

followed by
```
Could not start cover on 'rmq-ct-reader_SUITE-1-21000@localhost': {error,
                                                                   {already_started,
                                                                    <20798.286.0>}}
```

followed by
```
*** CT 2023-11-07 16:40:04.960 *** COVER INFO🔗
Successfully added nodes to cover test: []
```

followed by
```
Error in process <0.202.0> on node ct_rabbitmq_mqtt@nuc with exit value:
{{badmatch,{ok,[]}},
 [{rabbit_ct_broker_helpers,'-cover_add_node/1-fun-0-',1,
                            [{file,"rabbit_ct_broker_helpers.erl"},
                             {line,2211}]},
  {rabbit_ct_broker_helpers,query_node,2,
                            [{file,"rabbit_ct_broker_helpers.erl"},
                             {line,824}]},
  {rabbit_ct_broker_helpers,run_node_steps,4,
                            [{file,"rabbit_ct_broker_helpers.erl"},
                             {line,447}]},
  {rabbit_ct_broker_helpers,start_rabbitmq_node,4,
                            [{file,"rabbit_ct_broker_helpers.erl"},
```

It's also worth mentioning that
`make run-broker`
on v3.12.x:
```
  Starting broker... completed with 36 plugins.
1> whereis(cover_server).
undefined
```
but on main:
```
  Starting broker... completed with 36 plugins.
1> whereis(cover_server).
<0.295.0>
```
So, process `cover_server` runs on main in non test code.
This commit is contained in:
David Ansari 2023-11-08 09:41:00 +01:00
parent e52772057c
commit e99aa68ea4
1 changed files with 13 additions and 5 deletions

View File

@ -2208,6 +2208,11 @@ cover_add_node(Node)
when is_atom(Node) andalso Node =/= undefined ->
if_cover(
fun() ->
%% Dependency horus starts registered process cover_server on the RabbitMQ
%% node. If we weren't to stop that process first, ct_cover:add_nodes/1 would
%% print `{error, {already_started, _CoverServerPid}}` and return
%% `{ok, []}` resulting in no test coverage.
ok = erpc:call(Node, cover, stop, []),
{ok, [Node]} = ct_cover:add_nodes([Node])
end).
@ -2224,11 +2229,14 @@ cover_remove_node(Config, Node) ->
cover_remove_node(Nodename).
if_cover(F) ->
case os:getenv("COVER") of
false ->
ok;
_ ->
F()
case {
%% make ct COVER=1
os:getenv("COVER"),
%% bazel coverage
os:getenv("COVERAGE")
} of
{false, false} -> ok;
_ -> F()
end.
setup_meck(Config) ->