Skip to content

Support code coverage#6394

Merged
ansd merged 3 commits intomainfrom
cover
Nov 10, 2022
Merged

Support code coverage#6394
ansd merged 3 commits intomainfrom
cover

Conversation

@ansd
Copy link
Copy Markdown
Member

@ansd ansd commented Nov 9, 2022

Previously it was not possible to see code coverage for the majority of test cases: integration tests that create RabbitMQ nodes. It was only possible to see code coverage for unit tests. This commit allows to see code coverage for tests that create RabbitMQ nodes.

The only thing you need to do is setting the COVER variable, for example

make -C deps/rabbitmq_mqtt ct COVER=1

will show you coverage across all tests in the MQTT plugin.

This commit fixes the erlang.mk file that did not append the -cover <sepc_path> flag to the ct_run command.

Whenever a RabbitMQ node is started ct_cover:add_nodes/1 is called. Contrary to the documentation which states

To have effect, this function is to be called from init_per_suite/1 (see common_test) before any tests are performed.

I found that it also works in init_per_group/1 or even within the test cases themselves.

Whenever a RabbitMQ node is stopped or killed ct_cover:remove_nodes/1 is called to transfer results from the RabbitMQ node to the CT node.

Since the erlang.mk file writes a file called test/ct.cover.spec including the line:

{export,".../rabbitmq-server/deps/rabbitmq_mqtt/cover/ct.coverdata"}.

results across all test suites will be accumulated in that file.

The accumulated result can be seen through the link Coverage log on the test suite result pages.

@mergify mergify Bot added the make label Nov 9, 2022
@ansd ansd marked this pull request as ready for review November 9, 2022 17:56
@lhoguin
Copy link
Copy Markdown
Contributor

lhoguin commented Nov 10, 2022

Are you sure about the erlang.mk changes? Because there's tests confirming the file does what it should, at least in vanilla Erlang.mk. In any case they should be sent upstream at https://github.com/ninenines/erlang.mk

ansd added 2 commits November 10, 2022 13:26
Previously it was not possible to see code coverage for the majority of
test cases: integration tests that create RabbitMQ nodes.
It was only possible to see code coverage for unit tests.
This commit allows to see code coverage for tests that create RabbitMQ
nodes.

The only thing you need to do is setting the `COVER` variable, for example
```
make -C deps/rabbitmq_mqtt ct COVER=1
```
will show you coverage across all tests in the MQTT plugin.

Whenever a RabbitMQ node is started `ct_cover:add_nodes/1` is called.
Contrary to the documentation which states

> To have effect, this function is to be called from init_per_suite/1 (see common_test) before any tests are performed.

I found that it also works in init_per_group/1 or even within the test cases themselves.

Whenever a RabbitMQ node is stopped or killed `ct_cover:remove_nodes/1`
is called to transfer results from the RabbitMQ node to the CT node.

Since the erlang.mk file writes a file called `test/ct.cover.spec`
including the line:
```
{export,".../rabbitmq-server/deps/rabbitmq_mqtt/cover/ct.coverdata"}.
```
results across all test suites will be accumulated in that file.

The accumulated result can be seen through the link `Coverage log` on the test suite result pages.
by running
```
make erlang-mk
```

to include ninenines/erlang.mk@6423c1c
which provides test coverage for individual suites.
@ansd
Copy link
Copy Markdown
Member Author

ansd commented Nov 10, 2022

Thank you @lhoguin for fixing the erlang.mk part upstream via ninenines/erlang.mk@6423c1c
I just force pushed.

@ansd ansd marked this pull request as draft November 10, 2022 13:30
@ansd ansd marked this pull request as ready for review November 10, 2022 13:53
@ansd ansd merged commit 1b1a775 into main Nov 10, 2022
@ansd ansd deleted the cover branch November 10, 2022 14:04
@ansd ansd mentioned this pull request Sep 5, 2023
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants