浏览代码

Add tests for prevent silent dropping

pull/467/head
Rustam Safargalin 6 年前
父节点
当前提交
04a2471657
共有 2 个文件被更改,包括 51 次插入0 次删除
  1. +34
    -0
      src/error_logger_lager_h.erl
  2. +17
    -0
      src/lager_file_backend.erl

+ 34
- 0
src/error_logger_lager_h.erl 查看文件

@ -596,3 +596,37 @@ get_value(Key, List, Default) ->
supervisor_name({local, Name}) -> Name;
supervisor_name(Name) -> Name.
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
no_silent_hwm_drops_test_() ->
{timeout, 10000,
[
fun() ->
error_logger:tty(false),
application:load(lager),
application:set_env(lager, handlers, [{lager_test_backend, warning}]),
application:set_env(lager, error_logger_redirect, true),
application:set_env(lager, error_logger_hwm, 5),
application:set_env(lager, error_logger_flush_queue, false),
application:unset_env(lager, crash_log),
lager:start(),
try
{_, _, MS} = os:timestamp(),
timer:sleep((1000000 - MS) div 1000 + 1),
%start close to the beginning of a new second
[error_logger:error_msg("Foo ~p~n", [K]) || K <- lists:seq(1, 15)],
timer:sleep(1000),
lager_handler_watcher:pop_until("lager_error_logger_h dropped 10 messages in the last second that exceeded the limit of 5 messages/sec",
fun lists:flatten/1)
after
application:stop(lager),
application:stop(goldrush),
error_logger:tty(true)
end
end
]
}.
-endif.

+ 17
- 0
src/lager_file_backend.erl 查看文件

@ -957,6 +957,23 @@ filesystem_test_() ->
?assert(filelib:is_regular(TestLog0)),
lager_util:delete_test_dir(TestDir)
end},
{"no silent hwm drops",
fun() ->
TestDir = lager_util:create_test_dir(),
TestLog = filename:join(TestDir, "test.log"),
gen_event:add_handler(lager_event, lager_file_backend, [{file, TestLog}, {level, info},
{high_water_mark, 5}, {flush_queue, false}, {sync_on, "=warning"}]),
{_, _, MS} = os:timestamp(),
timer:sleep((1000000 - MS) div 1000 + 1),
%start close to the beginning of a new second
[lager:log(info, self(), "Foo ~p", [K]) || K <- lists:seq(1, 15)],
timer:sleep(1000),
{ok, Bin} = file:read_file(TestLog),
Last = lists:last(re:split(Bin, "\n", [{return, list}, trim])),
?assertMatch([_, _, _, _, "lager_file_backend dropped 10 messages in the last second that exceeded the limit of 5 messages/sec"],
re:split(Last, " ", [{return, list}, {parts, 5}])),
lager_util:delete_test_dir(TestDir)
end}
]}.

正在加载...
取消
保存