diff options
author | David Ansari <david.ansari@gmx.de> | 2022-11-10 13:26:25 +0100 |
---|---|---|
committer | David Ansari <david.ansari@gmx.de> | 2022-11-10 15:49:51 +0100 |
commit | 559d0093f379065a731aa425d450face2a1f7578 (patch) | |
tree | 7eb0386bcd5134ed4df4d6dde66cc7678e4ca839 | |
parent | 0a2e19d597a830a36e8be7a4dd85669a919b2c76 (diff) | |
download | rabbitmq-server-git-559d0093f379065a731aa425d450face2a1f7578.tar.gz |
Support code coverage
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.
(cherry picked from commit 5bf819298214e2f5d58e8c775693633502fdb3a8)
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | deps/rabbit/test/direct_exchange_routing_v2_SUITE.erl | 3 | ||||
-rw-r--r-- | deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl | 26 | ||||
-rw-r--r-- | deps/rabbitmq_mqtt/.gitignore | 2 |
4 files changed, 28 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore index 968e94a2c3..c0d31cb8d1 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ /plugins.lock /sbin/ /sbin.lock +ct.cover.spec erl_crash.dump rebar3.crashdump .envrc diff --git a/deps/rabbit/test/direct_exchange_routing_v2_SUITE.erl b/deps/rabbit/test/direct_exchange_routing_v2_SUITE.erl index 707a21e8f8..c125b1766e 100644 --- a/deps/rabbit/test/direct_exchange_routing_v2_SUITE.erl +++ b/deps/rabbit/test/direct_exchange_routing_v2_SUITE.erl @@ -321,8 +321,7 @@ recover_bindings(Config) -> assert_index_table_empty(Config), rabbit_ct_broker_helpers:rabbitmqctl(Config, Server, ["import_definitions", Path], 10_000), ?assertEqual(?NUM_BINDINGS_TO_DIRECT_ECHANGE, table_size(Config, ?INDEX_TABLE_NAME)), - ok = rabbit_ct_broker_helpers:stop_node(Config, 0), - ok = rabbit_ct_broker_helpers:start_node(Config, 0), + ok = rabbit_ct_broker_helpers:restart_node(Config, 0), ?assertEqual(?NUM_BINDINGS_TO_DIRECT_ECHANGE_DURABLE, table_size(Config, ?INDEX_TABLE_NAME)), %% cleanup diff --git a/deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl b/deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl index 3ace81f007..faecf4a30e 100644 --- a/deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl +++ b/deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl @@ -805,6 +805,7 @@ query_node(Config, NodeConfig) -> ct:pal("NO RABBITMQ_FEATURE_FLAGS_FILE"), Vars0 end, + cover_add_node(Nodename), rabbit_ct_helpers:set_config(NodeConfig, Vars). maybe_cluster_nodes(Config) -> @@ -1002,9 +1003,10 @@ stop_rabbitmq_nodes(Config) -> proplists:delete(rmq_nodes, Config). stop_rabbitmq_node(Config, NodeConfig) -> + Nodename = ?config(nodename, NodeConfig), + cover_remove_node(Nodename), SrcDir = ?config(effective_srcdir, NodeConfig), InitialMakeVars = ?config(make_vars_for_node_startup, NodeConfig), - Nodename = ?config(nodename, NodeConfig), InitialNodename = ?config(initial_nodename, NodeConfig), MakeVars = InitialMakeVars ++ [ {"RABBITMQ_NODENAME=~s", [Nodename]}, @@ -1626,7 +1628,7 @@ stop_node_after(Config, Node, Sleep) -> kill_node(Config, Node) -> Pid = rpc(Config, Node, os, getpid, []), - %% FIXME maybe_flush_cover(Cfg), + cover_remove_node(Node), Cmd = case os:type() of {win32, _} -> case os:find_executable("taskkill.exe") of @@ -1917,3 +1919,23 @@ user(Username) -> #user{username = Username, tags = [administrator], authz_backends = [{rabbit_auth_backend_internal, none}]}. + +cover_add_node(Node) -> + if_cover( + fun() -> + {ok, [Node]} = ct_cover:add_nodes([Node]) + end). + +cover_remove_node(Node) -> + if_cover( + fun() -> + ok = ct_cover:remove_nodes([Node]) + end). + +if_cover(F) -> + case os:getenv("COVER") of + false -> + ok; + _ -> + F() + end. diff --git a/deps/rabbitmq_mqtt/.gitignore b/deps/rabbitmq_mqtt/.gitignore index 4ef626d07e..42376fc0ad 100644 --- a/deps/rabbitmq_mqtt/.gitignore +++ b/deps/rabbitmq_mqtt/.gitignore @@ -1,6 +1,7 @@ .sw? .*.sw? *.beam +*.coverdata .idea/* /.erlang.mk/ /cover/ @@ -15,6 +16,7 @@ /plugins.lock /sbin/ /sbin.lock +/test/ct.cover.spec /xrefr debug/* *.plt |