Skip to content

Commit 5da43ea

Browse files
committed
Reduce the amount of printing to the terminal during tests
1 parent 0384a82 commit 5da43ea

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ run_make_dist(Config) ->
275275
end;
276276
_ ->
277277
global:del_lock(LockId, [node()]),
278-
ct:pal(?LOW_IMPORTANCE, "(skip `$MAKE test-dist`)", []),
278+
ct:log(?LOW_IMPORTANCE, "(skip `$MAKE test-dist`)", []),
279279
Config
280280
end.
281281

@@ -819,7 +819,7 @@ query_node(Config, NodeConfig) ->
819819
%% 3.7.x node. If this is the case, we can ignore
820820
%% this and leave the `enabled_plugins_file` config
821821
%% variable unset.
822-
ct:pal("NO RABBITMQ_FEATURE_FLAGS_FILE"),
822+
ct:log("NO RABBITMQ_FEATURE_FLAGS_FILE"),
823823
Vars0
824824
end,
825825
cover_add_node(Nodename),
@@ -883,7 +883,7 @@ handle_nodes_in_parallel(NodeConfigs, Fun) ->
883883
T1 = erlang:monotonic_time(),
884884
Ret = Fun(NodeConfig),
885885
T2 = erlang:monotonic_time(),
886-
ct:pal(
886+
ct:log(
887887
?LOW_IMPORTANCE,
888888
"Time to run ~tp for node ~ts: ~b us",
889889
[Fun,
@@ -901,7 +901,7 @@ handle_nodes_in_parallel(NodeConfigs, Fun) ->
901901

902902
wait_for_node_handling([], Fun, T0, Results) ->
903903
T3 = erlang:monotonic_time(),
904-
ct:pal(
904+
ct:log(
905905
?LOW_IMPORTANCE,
906906
"Time to run ~tp for all nodes: ~b us",
907907
[Fun, erlang:convert_time_unit(T3 - T0, native, microsecond)]),
@@ -956,7 +956,7 @@ configured_metadata_store(Config) ->
956956
end.
957957

958958
configure_metadata_store(Config) ->
959-
ct:pal("Configuring metadata store..."),
959+
ct:log("Configuring metadata store..."),
960960
case configured_metadata_store(Config) of
961961
{khepri, FFs0} ->
962962
case enable_khepri_metadata_store(Config, FFs0) of
@@ -967,12 +967,12 @@ configure_metadata_store(Config) ->
967967
Config1
968968
end;
969969
mnesia ->
970-
ct:pal("Enabling Mnesia metadata store"),
970+
ct:log("Enabling Mnesia metadata store"),
971971
Config
972972
end.
973973

974974
enable_khepri_metadata_store(Config, FFs0) ->
975-
ct:pal("Enabling Khepri metadata store"),
975+
ct:log("Enabling Khepri metadata store"),
976976
FFs = [khepri_db | FFs0],
977977
lists:foldl(fun(_FF, {skip, _Reason} = Skip) ->
978978
Skip;
@@ -1143,7 +1143,7 @@ stop_rabbitmq_node(Config, NodeConfig) ->
11431143
NodeConfig.
11441144

11451145
find_crashes_in_logs(NodeConfigs, IgnoredCrashes) ->
1146-
ct:pal(
1146+
ct:log(
11471147
"Looking up any crash reports in the nodes' log files. If we find "
11481148
"some, they will appear below:"),
11491149
CrashesCount = lists:foldl(
@@ -1152,7 +1152,11 @@ find_crashes_in_logs(NodeConfigs, IgnoredCrashes) ->
11521152
NodeConfig, IgnoredCrashes),
11531153
Total + Count
11541154
end, 0, NodeConfigs),
1155-
ct:pal("Found ~b crash report(s)", [CrashesCount]),
1155+
LogFn = case CrashesCount of
1156+
0 -> log;
1157+
_ -> pal
1158+
end,
1159+
ct:LogFn("Found ~b crash report(s)", [CrashesCount]),
11561160
?assertEqual(0, CrashesCount).
11571161

11581162
count_crashes_in_logs(NodeConfig, IgnoredCrashes) ->

deps/rabbitmq_ct_helpers/src/rabbit_ct_helpers.erl

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767
log_environment() ->
6868
Vars = lists:sort(fun(A, B) -> A =< B end, os:getenv()),
69-
ct:pal(?LOW_IMPORTANCE, "Environment variables:~n~ts",
69+
ct:log(?LOW_IMPORTANCE, "Environment variables:~n~ts",
7070
[[io_lib:format(" ~ts~n", [V]) || V <- Vars]]).
7171

7272
run_setup_steps(Config) ->
@@ -152,7 +152,7 @@ run_steps(Config, []) ->
152152
Config.
153153

154154
redirect_logger_to_ct_logs(Config) ->
155-
ct:pal(
155+
ct:log(
156156
?LOW_IMPORTANCE,
157157
"Configuring logger to send logs to common_test logs"),
158158
ok = logger:set_handler_config(cth_log_redirect, level, debug),
@@ -172,7 +172,7 @@ redirect_logger_to_ct_logs(Config) ->
172172

173173
ok = logger:remove_handler(default),
174174

175-
ct:pal(
175+
ct:log(
176176
?LOW_IMPORTANCE,
177177
"Logger configured to send logs to common_test logs; you should see "
178178
"a message below saying so"),
@@ -433,12 +433,12 @@ ensure_rabbitmqctl_cmd(Config) ->
433433
false ->
434434
find_script(Config, "rabbitmqctl");
435435
R ->
436-
ct:pal(?LOW_IMPORTANCE,
436+
ct:log(?LOW_IMPORTANCE,
437437
"Using rabbitmqctl from RABBITMQCTL: ~tp~n", [R]),
438438
R
439439
end;
440440
R ->
441-
ct:pal(?LOW_IMPORTANCE,
441+
ct:log(?LOW_IMPORTANCE,
442442
"Using rabbitmqctl from rabbitmqctl_cmd: ~tp~n", [R]),
443443
R
444444
end,
@@ -470,7 +470,7 @@ find_script(Config, Script) ->
470470
filelib:is_file(File)],
471471
case Locations of
472472
[Location | _] ->
473-
ct:pal(?LOW_IMPORTANCE, "Using ~ts at ~tp~n", [Script, Location]),
473+
ct:log(?LOW_IMPORTANCE, "Using ~ts at ~tp~n", [Script, Location]),
474474
Location;
475475
[] ->
476476
false
@@ -555,7 +555,7 @@ ensure_rabbitmq_queues_cmd(Config) ->
555555
R -> R
556556
end;
557557
R ->
558-
ct:pal(?LOW_IMPORTANCE,
558+
ct:log(?LOW_IMPORTANCE,
559559
"Using rabbitmq-queues from rabbitmq_queues_cmd: ~tp~n", [R]),
560560
R
561561
end,
@@ -654,12 +654,12 @@ symlink_priv_dir(Config) ->
654654
Target = filename:join([SrcDir, "logs", Name]),
655655
case exec(["ln", "-snf", PrivDir, Target]) of
656656
{ok, _} -> ok;
657-
_ -> ct:pal(?LOW_IMPORTANCE,
657+
_ -> ct:log(?LOW_IMPORTANCE,
658658
"Failed to symlink private_log directory.")
659659
end,
660660
Config;
661661
not_found ->
662-
ct:pal(?LOW_IMPORTANCE,
662+
ct:log(?LOW_IMPORTANCE,
663663
"Failed to symlink private_log directory."),
664664
Config
665665
end
@@ -684,7 +684,7 @@ load_elixir(Config) ->
684684
{skip, _} = Skip ->
685685
Skip;
686686
ElixirLibDir ->
687-
ct:pal(?LOW_IMPORTANCE, "Elixir lib dir: ~ts~n", [ElixirLibDir]),
687+
ct:log(?LOW_IMPORTANCE, "Elixir lib dir: ~ts~n", [ElixirLibDir]),
688688
true = code:add_pathz(ElixirLibDir),
689689
{ok, _} = application:ensure_all_started(elixir),
690690
Config
@@ -720,14 +720,18 @@ long_running_testsuite_monitor(TimerRef, Testcases) ->
720720
long_running_testsuite_monitor(TimerRef, Testcases1);
721721
ping_ct ->
722722
T1 = erlang:monotonic_time(seconds),
723-
ct:pal(?STD_IMPORTANCE, "Testcases still in progress:~ts",
724-
[[
723+
InProgress = [
725724
begin
726725
TDiff = format_time_diff(T1, T0),
727726
rabbit_misc:format("~n - ~ts (~ts)", [TC, TDiff])
728727
end
729728
|| {TC, T0} <- Testcases
730-
]]),
729+
],
730+
case InProgress of
731+
[] -> ok;
732+
_ -> ct:pal(?STD_IMPORTANCE, "Testcases still in progress:~ts",
733+
[InProgress])
734+
end,
731735
long_running_testsuite_monitor(TimerRef, Testcases);
732736
stop ->
733737
timer:cancel(TimerRef)
@@ -905,7 +909,7 @@ exec([Cmd | Args], Options) when is_list(Cmd) orelse is_binary(Cmd) ->
905909
%% Because Args1 may contain binaries, we don't use string:join().
906910
%% Instead we do a list comprehension.
907911
ArgsIoList = [Cmd1, [[$\s, Arg] || Arg <- Args1]],
908-
ct:pal(?LOW_IMPORTANCE, Log1, [ArgsIoList, self()]),
912+
ct:log(?LOW_IMPORTANCE, Log1, [ArgsIoList, self()]),
909913
try
910914
Port = erlang:open_port(
911915
{spawn_executable, Cmd1}, [
@@ -951,10 +955,10 @@ port_receive_loop(Port, Stdout, Options, Until, DumpTimer) ->
951955
Stdout =:= "",
952956
if
953957
DropStdout ->
954-
ct:pal(?LOW_IMPORTANCE, "Exit code: ~tp (pid ~tp)",
958+
ct:log(?LOW_IMPORTANCE, "Exit code: ~tp (pid ~tp)",
955959
[X, self()]);
956960
true ->
957-
ct:pal(?LOW_IMPORTANCE, "~ts~nExit code: ~tp (pid ~tp)",
961+
ct:log(?LOW_IMPORTANCE, "~ts~nExit code: ~tp (pid ~tp)",
958962
[Stdout, X, self()])
959963
end,
960964
case proplists:get_value(match_stdout, Options) of
@@ -976,7 +980,7 @@ port_receive_loop(Port, Stdout, Options, Until, DumpTimer) ->
976980
DropStdout ->
977981
ok;
978982
true ->
979-
ct:pal(?LOW_IMPORTANCE, "~ts~n[Command still in progress] (pid ~tp)",
983+
ct:log(?LOW_IMPORTANCE, "~ts~n[Command still in progress] (pid ~tp)",
980984
[Stdout, self()])
981985
end,
982986
port_receive_loop(Port, Stdout, Options, Until, stdout_dump_timer());
@@ -1101,7 +1105,7 @@ eventually({Line, Assertion} = TestObj, PollInterval, PollCount)
11011105
ok ->
11021106
ok;
11031107
Err ->
1104-
ct:pal(?LOW_IMPORTANCE,
1108+
ct:log(?LOW_IMPORTANCE,
11051109
"Retrying in ~bms for ~b more times due to failed assertion in line ~b: ~tp",
11061110
[PollInterval, PollCount - 1, Line, Err]),
11071111
timer:sleep(PollInterval),

0 commit comments

Comments
 (0)