From 752733b093fdb8cdbeea09abed9d462b825669be Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Wed, 12 Feb 2014 12:22:42 -0500 Subject: [PATCH] Make tests pass on buildbot more of the time --- src/lager_console_backend.erl | 2 ++ src/lager_crash_log.erl | 1 + src/lager_file_backend.erl | 4 +++- src/lager_handler_watcher.erl | 2 ++ src/lager_util.erl | 1 + test/lager_test_backend.erl | 13 ++++++++++--- 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/lager_console_backend.erl b/src/lager_console_backend.erl index 4d9c4e3..44cfd5a 100644 --- a/src/lager_console_backend.erl +++ b/src/lager_console_backend.erl @@ -175,6 +175,7 @@ console_log_test_() -> unregister(user), register(user, User), application:stop(lager), + application:stop(goldrush), error_logger:tty(true) end, [ @@ -388,6 +389,7 @@ set_loglevel_test_() -> end, fun(_) -> application:stop(lager), + application:stop(goldrush), error_logger:tty(true) end, [ diff --git a/src/lager_crash_log.erl b/src/lager_crash_log.erl index 9ccbc7f..d0456c4 100644 --- a/src/lager_crash_log.erl +++ b/src/lager_crash_log.erl @@ -253,6 +253,7 @@ filesystem_test_() -> end, file:delete("crash_test.log"), application:stop(lager), + application:stop(goldrush), error_logger:tty(true) end, [ diff --git a/src/lager_file_backend.erl b/src/lager_file_backend.erl index 96f41bc..bd7dcfb 100644 --- a/src/lager_file_backend.erl +++ b/src/lager_file_backend.erl @@ -476,6 +476,7 @@ filesystem_test_() -> file:delete("test.log.0"), file:delete("test.log.1"), application:stop(lager), + application:stop(goldrush), error_logger:tty(true) end, [ @@ -607,7 +608,7 @@ filesystem_test_() -> ?assertEqual({ok, <<>>}, file:read_file("test.log")), lager:log(info, self(), "Test message1"), ?assertEqual({ok, <<>>}, file:read_file("test.log")), - timer:sleep(1000), + timer:sleep(2000), {ok, Bin} = file:read_file("test.log"), ?assert(<<>> /= Bin) end @@ -722,6 +723,7 @@ formatting_test_() -> file:delete("test.log"), file:delete("test2.log"), application:stop(lager), + application:stop(goldrush), error_logger:tty(true) end, [{"Should have two log files, the second prefixed with 2>", diff --git a/src/lager_handler_watcher.erl b/src/lager_handler_watcher.erl index 1285a24..24498a4 100644 --- a/src/lager_handler_watcher.erl +++ b/src/lager_handler_watcher.erl @@ -134,6 +134,7 @@ reinstall_on_initial_failure_test_() -> ?assert(lists:member(lager_crash_backend, gen_event:which_handlers(lager_event))) after application:stop(lager), + application:stop(goldrush), error_logger:tty(true) end end @@ -162,6 +163,7 @@ reinstall_on_runtime_failure_test_() -> ?assertEqual(false, lists:member(lager_crash_backend, gen_event:which_handlers(lager_event))) after application:stop(lager), + application:stop(goldrush), error_logger:tty(true) end end diff --git a/src/lager_util.erl b/src/lager_util.erl index d912103..67894ff 100644 --- a/src/lager_util.erl +++ b/src/lager_util.erl @@ -629,6 +629,7 @@ check_trace_test() -> {[{module, '*'}], config_to_mask('!=notice'), anythingbutnotice} ], [])), application:stop(lager), + application:stop(goldrush), ok. is_loggable_test_() -> diff --git a/test/lager_test_backend.erl b/test/lager_test_backend.erl index 648bdb9..f0aea2e 100644 --- a/test/lager_test_backend.erl +++ b/test/lager_test_backend.erl @@ -511,7 +511,7 @@ lager_test_() -> {"record printing fails gracefully when module is invalid", fun() -> spawn(fun() -> lager:info("State ~p", [lager:pr({state, 1}, not_a_module)]) end), - timer:sleep(100), + timer:sleep(1000), {Level, _Time, Message, _Metadata} = pop(), ?assertMatch(Level, lager_util:level_to_num(info)), ?assertEqual("State {state,1}", lists:flatten(Message)), @@ -566,6 +566,7 @@ setup() -> cleanup(_) -> application:stop(lager), + application:stop(goldrush), error_logger:tty(true). @@ -620,6 +621,7 @@ error_logger_redirect_crash_test_() -> fun(_) -> application:stop(lager), + application:stop(goldrush), case whereis(crash) of undefined -> ok; Pid -> exit(Pid, kill) @@ -669,6 +671,7 @@ error_logger_redirect_test_() -> fun(_) -> application:stop(lager), + application:stop(goldrush), error_logger:tty(true) end, [ @@ -1158,13 +1161,15 @@ async_threshold_test_() -> error_logger:tty(false), application:load(lager), application:set_env(lager, error_logger_redirect, false), - application:set_env(lager, async_threshold, 10), + application:set_env(lager, async_threshold, 2), + application:set_env(lager, async_threshold_window, 1), application:set_env(lager, handlers, [{?MODULE, info}]), lager:start() end, fun(_) -> application:unset_env(lager, async_threshold), application:stop(lager), + application:stop(goldrush), error_logger:tty(true) end, [ @@ -1186,7 +1191,9 @@ async_threshold_test_() -> %% serialize ont the mailbox again _ = gen_event:which_handlers(lager_event), %% just in case... - timer:sleep(100), + timer:sleep(1000), + lager:info("hello world"), + _ = gen_event:which_handlers(lager_event), %% async is true again now that the mailbox has drained ?assertEqual(true, lager_config:get(async)),