From e37e6b646ec5c64703b90530e252afe619bee56c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 15 Oct 2024 12:19:08 +0200 Subject: [PATCH] Make CI: Have ct_master return the test results Instead of having a CT hook just to know whether our tests failed. --- deps/rabbit/Makefile | 22 ++++++------------ .../src/ct_master_fork.erl | 10 ++++---- .../src/cth_parallel_ct_detect_failure.erl | 23 ------------------- deps/rabbitmq_mqtt/Makefile | 22 ++++++------------ 4 files changed, 19 insertions(+), 58 deletions(-) delete mode 100644 deps/rabbitmq_ct_helpers/src/cth_parallel_ct_detect_failure.erl diff --git a/deps/rabbit/Makefile b/deps/rabbit/Makefile index e5ac5bb0401..da1d32fe52c 100644 --- a/deps/rabbit/Makefile +++ b/deps/rabbit/Makefile @@ -239,22 +239,16 @@ define ct_master.erl peer:call(Pid2, persistent_term, put, [rabbit_ct_tcp_port_base, 25000]), peer:call(Pid3, persistent_term, put, [rabbit_ct_tcp_port_base, 27000]), peer:call(Pid4, persistent_term, put, [rabbit_ct_tcp_port_base, 29000]), - ct_master_fork:run("$1"), - Fail1 = peer:call(Pid1, cth_parallel_ct_detect_failure, has_failures, []), - Fail2 = peer:call(Pid2, cth_parallel_ct_detect_failure, has_failures, []), - Fail3 = peer:call(Pid3, cth_parallel_ct_detect_failure, has_failures, []), - Fail4 = peer:call(Pid4, cth_parallel_ct_detect_failure, has_failures, []), + [{[_], {ok, Results}}] = ct_master_fork:run("$1"), peer:stop(Pid4), peer:stop(Pid3), peer:stop(Pid2), peer:stop(Pid1), - if - Fail1 -> halt(1); - Fail2 -> halt(2); - Fail3 -> halt(3); - Fail4 -> halt(4); - true -> halt(0) - end + lists:foldl(fun + ({_, {_, 0, {_, 0}}}, Err) -> Err + 1; + (What, Peer) -> halt(Peer) + end, 1, Results), + halt(0) endef PARALLEL_CT_SET_1_A = amqp_client unit_cluster_formation_locking_mocks unit_cluster_formation_sort_nodes unit_collections unit_config_value_encryption unit_connection_tracking @@ -293,15 +287,13 @@ define tpl_parallel_ct_test_spec {logdir, "$(CT_LOGS_DIR)"}. {logdir, master, "$(CT_LOGS_DIR)"}. {create_priv_dir, all_nodes, auto_per_run}. +{auto_compile, false}. {node, shard1, 'rabbit_shard1@localhost'}. {node, shard2, 'rabbit_shard2@localhost'}. {node, shard3, 'rabbit_shard3@localhost'}. {node, shard4, 'rabbit_shard4@localhost'}. -{auto_compile, false}. -{ct_hooks, [cth_parallel_ct_detect_failure]}. - {define, 'Set1', [$(call comma_list,$(addsuffix _SUITE,$1))]}. {define, 'Set2', [$(call comma_list,$(addsuffix _SUITE,$2))]}. {define, 'Set3', [$(call comma_list,$(addsuffix _SUITE,$3))]}. diff --git a/deps/rabbitmq_ct_helpers/src/ct_master_fork.erl b/deps/rabbitmq_ct_helpers/src/ct_master_fork.erl index 2735c359f90..0661635f4e5 100644 --- a/deps/rabbitmq_ct_helpers/src/ct_master_fork.erl +++ b/deps/rabbitmq_ct_helpers/src/ct_master_fork.erl @@ -392,8 +392,7 @@ run_all([],#testspec{ end, log(tty,"Master Logdir","~ts",[MasterLogDir]), start_master(lists:reverse(NodeOpts),Handlers,MasterLogDir, - LogDirsRun,InitOptions,Specs), - ok. + LogDirsRun,InitOptions,Specs). %-doc """ @@ -581,18 +580,19 @@ init_master2(Parent,NodeOptsList,LogDirs) -> Parent ! {self(),Result}. master_loop(#state{node_ctrl_pids=[], - results=Finished}) -> + results=Finished0}) -> + Finished = lists:sort(Finished0), Str = lists:map(fun({Node,Result}) -> io_lib:format("~-40.40.*ts~tp\n", [$_,atom_to_list(Node),Result]) - end,lists:sort(Finished)), + end,Finished), log(all,"TEST RESULTS","~ts", [Str]), log(all,"Info","Updating log files",[]), ct_master_event_fork:stop(), ct_master_logs_fork:stop(), - ok; + {ok, Finished}; master_loop(State=#state{node_ctrl_pids=NodeCtrlPids, results=Results, diff --git a/deps/rabbitmq_ct_helpers/src/cth_parallel_ct_detect_failure.erl b/deps/rabbitmq_ct_helpers/src/cth_parallel_ct_detect_failure.erl deleted file mode 100644 index 428e37468bf..00000000000 --- a/deps/rabbitmq_ct_helpers/src/cth_parallel_ct_detect_failure.erl +++ /dev/null @@ -1,23 +0,0 @@ --module(cth_parallel_ct_detect_failure). - --export([init/2]). --export([on_tc_fail/4]). --export([has_failures/0]). - -init(_Id, _Opts) -> - {ok, undefined}. - -%% We silence failures in end_per_suite/end_per_group -%% to mirror the default behavior. It should be modified -%% so that they are configured failures as well, but can -%% be done at a later time. -on_tc_fail(_SuiteName, end_per_suite, _Reason, CTHState) -> - CTHState; -on_tc_fail(_SuiteName, {end_per_group, _GroupName}, _Reason, CTHState) -> - CTHState; -on_tc_fail(_SuiteName, _TestName, _Reason, CTHState) -> - persistent_term:put(?MODULE, true), - CTHState. - -has_failures() -> - persistent_term:get(?MODULE, false). diff --git a/deps/rabbitmq_mqtt/Makefile b/deps/rabbitmq_mqtt/Makefile index 72dee7bba79..6a74a6a80c9 100644 --- a/deps/rabbitmq_mqtt/Makefile +++ b/deps/rabbitmq_mqtt/Makefile @@ -82,22 +82,16 @@ define ct_master.erl peer:call(Pid2, persistent_term, put, [rabbit_ct_tcp_port_base, 25000]), peer:call(Pid3, persistent_term, put, [rabbit_ct_tcp_port_base, 27000]), peer:call(Pid4, persistent_term, put, [rabbit_ct_tcp_port_base, 29000]), - ct_master_fork:run("$1"), - Fail1 = peer:call(Pid1, cth_parallel_ct_detect_failure, has_failures, []), - Fail2 = peer:call(Pid2, cth_parallel_ct_detect_failure, has_failures, []), - Fail3 = peer:call(Pid3, cth_parallel_ct_detect_failure, has_failures, []), - Fail4 = peer:call(Pid4, cth_parallel_ct_detect_failure, has_failures, []), + [{[_], {ok, Results}}] = ct_master_fork:run("$1"), peer:stop(Pid4), peer:stop(Pid3), peer:stop(Pid2), peer:stop(Pid1), - if - Fail1 -> halt(1); - Fail2 -> halt(2); - Fail3 -> halt(3); - Fail4 -> halt(4); - true -> halt(0) - end + lists:foldl(fun + ({_, {_, 0, {_, 0}}}, Err) -> Err + 1; + (What, Peer) -> halt(Peer) + end, 1, Results), + halt(0) endef PARALLEL_CT_SET_1_A = auth retainer @@ -116,15 +110,13 @@ define tpl_parallel_ct_test_spec {logdir, "$(CT_LOGS_DIR)"}. {logdir, master, "$(CT_LOGS_DIR)"}. {create_priv_dir, all_nodes, auto_per_run}. +{auto_compile, false}. {node, shard1, 'rabbit_shard1@localhost'}. {node, shard2, 'rabbit_shard2@localhost'}. {node, shard3, 'rabbit_shard3@localhost'}. {node, shard4, 'rabbit_shard4@localhost'}. -{auto_compile, false}. -{ct_hooks, [cth_parallel_ct_detect_failure]}. - {define, 'Set1', [$(call comma_list,$(addsuffix _SUITE,$1))]}. {define, 'Set2', [$(call comma_list,$(addsuffix _SUITE,$2))]}. {define, 'Set3', [$(call comma_list,$(addsuffix _SUITE,$3))]}.