summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Kuryloski <pkuryloski@pivotal.io>2020-04-20 15:23:42 +0200
committerJean-Sébastien Pédron <jean-sebastien@rabbitmq.com>2020-04-21 15:18:42 +0200
commitde224081cb8fe3a260ab42ef27530c109e6a5085 (patch)
tree90f5392782ee67252a519e386dc34b65460ab069
parentc139e2f3ea7dd8aa8c90f5917c1e0526c2790fa8 (diff)
downloadrabbitmq-server-git-de224081cb8fe3a260ab42ef27530c109e6a5085.tar.gz
Attempt to make unit_log_managment_SUITE less flaky
Rather than wait a fixed 2000ms, poll the test condition for up to 5000ms. Also switch from a raw message send in rabbit.erl to a gen_event:call/4 to the lager backend. I had hoped this would behave synchronously, which it does not appear to, but at least we now get a value back from the call.
-rw-r--r--src/rabbit.erl11
-rw-r--r--test/unit_log_management_SUITE.erl30
2 files changed, 27 insertions, 14 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index b806eb8a17..e109c10c46 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -798,10 +798,13 @@ rotate_logs() ->
%% lager_file_backend. We should use a proper API, when
%% it's added to Lager.
%%
- %% FIXME: This message is asynchronous, therefore this
- %% entire call is asynchronous: at the end of this
- %% function, we can't guaranty the rotation is completed.
- [SinkName ! {rotate, FileName} || FileName <- FileNames],
+ %% FIXME: This call is effectively asynchronous: at the
+ %% end of this function, we can't guaranty the rotation
+ %% is completed.
+ [ok = gen_event:call(SinkName,
+ {lager_file_backend, FileName},
+ rotate,
+ infinity) || FileName <- FileNames],
lager:log(SinkName, info, self(),
"Log file re-opened after forced rotation", []),
Acc
diff --git a/test/unit_log_management_SUITE.erl b/test/unit_log_management_SUITE.erl
index 07177b10d6..31d96f38c2 100644
--- a/test/unit_log_management_SUITE.erl
+++ b/test/unit_log_management_SUITE.erl
@@ -138,26 +138,36 @@ log_management1(_Config) ->
%% simple log rotation
ok = rabbit:rotate_logs(),
- %% FIXME: rabbit:rotate_logs/0 is asynchronous due to a limitation
- %% in Lager. Therefore, we have no choice but to wait an arbitrary
+ %% rabbit:rotate_logs/0 is asynchronous due to a limitation in
+ %% Lager. Therefore, we have no choice but to wait an arbitrary
%% amount of time.
- timer:sleep(2000),
- [true, true] = non_empty_files([LogFile ++ Suffix, LogFile]),
+ ok = rabbit_ct_helpers:await_condition(
+ fun() ->
+ [true, true] =:=
+ non_empty_files([LogFile ++ Suffix, LogFile])
+ end, 5000),
ok = test_logs_working([LogFile]),
%% log rotation on empty files
ok = clean_logs([LogFile], Suffix),
ok = rabbit:rotate_logs(),
- timer:sleep(2000),
- ?assertEqual([true, true], non_empty_files([LogFile ++ Suffix, LogFile])),
+ ok = rabbit_ct_helpers:await_condition(
+ fun() ->
+ [true, true] =:=
+ non_empty_files([LogFile ++ Suffix, LogFile])
+ end, 5000),
%% logs with suffix are not writable
ok = rabbit:rotate_logs(),
- timer:sleep(2000),
- ok = make_files_non_writable([LogFile ++ Suffix]),
+ ok = rabbit_ct_helpers:await_condition(
+ fun() ->
+ ok =:= make_files_non_writable([LogFile ++ Suffix])
+ end, 5000),
ok = rabbit:rotate_logs(),
- timer:sleep(2000),
- ok = test_logs_working([LogFile]),
+ ok = rabbit_ct_helpers:await_condition(
+ fun() ->
+ ok =:= test_logs_working([LogFile])
+ end, 5000),
%% rotate when original log files are not writable
ok = make_files_non_writable([LogFile]),