浏览代码

Add some tests to test for the bug the previous commit fixed

pull/113/merge
Andrew Thompson 12 年前
父节点
当前提交
c237e6fde9
共有 1 个文件被更改,包括 17 次插入0 次删除
  1. +17
    -0
      test/lager_test_backend.erl

+ 17
- 0
test/lager_test_backend.erl 查看文件

@ -311,6 +311,7 @@ lager_test_() ->
?assertEqual(0, count()), ?assertEqual(0, count()),
?assertEqual(1, count_ignored()), ?assertEqual(1, count_ignored()),
lager:set_loglevel(?MODULE, debug), lager:set_loglevel(?MODULE, debug),
?assertEqual({?DEBUG bor ?INFO bor ?NOTICE bor ?WARNING bor ?ERROR bor ?CRITICAL bor ?ALERT bor ?EMERGENCY, []}, lager_config:get(loglevel)),
lager:debug("this message should be logged"), lager:debug("this message should be logged"),
?assertEqual(1, count()), ?assertEqual(1, count()),
?assertEqual(1, count_ignored()), ?assertEqual(1, count_ignored()),
@ -324,6 +325,7 @@ lager_test_() ->
ok = lager:info("hello world"), ok = lager:info("hello world"),
?assertEqual(0, count()), ?assertEqual(0, count()),
lager:trace(?MODULE, [{module, ?MODULE}], debug), lager:trace(?MODULE, [{module, ?MODULE}], debug),
?assertMatch({?ERROR bor ?CRITICAL bor ?ALERT bor ?EMERGENCY, _}, lager_config:get(loglevel)),
%% elegible for tracing %% elegible for tracing
ok = lager:info("hello world"), ok = lager:info("hello world"),
%% NOT elegible for tracing %% NOT elegible for tracing
@ -335,6 +337,7 @@ lager_test_() ->
{"tracing works with custom attributes", {"tracing works with custom attributes",
fun() -> fun() ->
lager:set_loglevel(?MODULE, error), lager:set_loglevel(?MODULE, error),
?assertEqual({?ERROR bor ?CRITICAL bor ?ALERT bor ?EMERGENCY, []}, lager_config:get(loglevel)),
lager_config:set(loglevel, {element(2, lager_util:config_to_mask(error)), []}), lager_config:set(loglevel, {element(2, lager_util:config_to_mask(error)), []}),
lager:info([{requestid, 6}], "hello world"), lager:info([{requestid, 6}], "hello world"),
?assertEqual(0, count()), ?assertEqual(0, count()),
@ -353,6 +356,7 @@ lager_test_() ->
{"tracing honors loglevel", {"tracing honors loglevel",
fun() -> fun() ->
lager:set_loglevel(?MODULE, error), lager:set_loglevel(?MODULE, error),
?assertEqual({?ERROR bor ?CRITICAL bor ?ALERT bor ?EMERGENCY, []}, lager_config:get(loglevel)),
{ok, T} = lager:trace(?MODULE, [{module, ?MODULE}], notice), {ok, T} = lager:trace(?MODULE, [{module, ?MODULE}], notice),
ok = lager:info("hello world"), ok = lager:info("hello world"),
?assertEqual(0, count()), ?assertEqual(0, count()),
@ -412,6 +416,14 @@ lager_test_() ->
?assertEqual("State {state,1}", lists:flatten(Message)), ?assertEqual("State {state,1}", lists:flatten(Message)),
ok ok
end end
},
{"installing a new handler adjusts the global loglevel if necessary",
fun() ->
?assertEqual({?INFO bor ?NOTICE bor ?WARNING bor ?ERROR bor ?CRITICAL bor ?ALERT bor ?EMERGENCY, []}, lager_config:get(loglevel)),
supervisor:start_child(lager_handler_watcher_sup, [lager_event, {?MODULE, foo}, debug]),
?assertEqual({?DEBUG bor ?INFO bor ?NOTICE bor ?WARNING bor ?ERROR bor ?CRITICAL bor ?ALERT bor ?EMERGENCY, []}, lager_config:get(loglevel)),
ok
end
} }
] ]
}. }.
@ -765,6 +777,7 @@ error_logger_redirect_test_() ->
{"supervisor progress report", {"supervisor progress report",
fun() -> fun() ->
lager:set_loglevel(?MODULE, debug), lager:set_loglevel(?MODULE, debug),
?assertEqual({?DEBUG bor ?INFO bor ?NOTICE bor ?WARNING bor ?ERROR bor ?CRITICAL bor ?ALERT bor ?EMERGENCY, []}, lager_config:get(loglevel)),
sync_error_logger:info_report(progress, [{supervisor, {local, foo}}, {started, [{mfargs, {foo, bar, 1}}, {pid, baz}]}]), sync_error_logger:info_report(progress, [{supervisor, {local, foo}}, {started, [{mfargs, {foo, bar, 1}}, {pid, baz}]}]),
_ = gen_event:which_handlers(error_logger), _ = gen_event:which_handlers(error_logger),
{Level, _, Msg,Metadata} = pop(), {Level, _, Msg,Metadata} = pop(),
@ -776,6 +789,7 @@ error_logger_redirect_test_() ->
{"supervisor progress report with pid", {"supervisor progress report with pid",
fun() -> fun() ->
lager:set_loglevel(?MODULE, debug), lager:set_loglevel(?MODULE, debug),
?assertEqual({?DEBUG bor ?INFO bor ?NOTICE bor ?WARNING bor ?ERROR bor ?CRITICAL bor ?ALERT bor ?EMERGENCY, []}, lager_config:get(loglevel)),
sync_error_logger:info_report(progress, [{supervisor, somepid}, {started, [{mfargs, {foo, bar, 1}}, {pid, baz}]}]), sync_error_logger:info_report(progress, [{supervisor, somepid}, {started, [{mfargs, {foo, bar, 1}}, {pid, baz}]}]),
_ = gen_event:which_handlers(error_logger), _ = gen_event:which_handlers(error_logger),
{Level, _, Msg,Metadata} = pop(), {Level, _, Msg,Metadata} = pop(),
@ -914,16 +928,19 @@ error_logger_redirect_test_() ->
{"messages should not be generated if they don't satisfy the threshold", {"messages should not be generated if they don't satisfy the threshold",
fun() -> fun() ->
lager:set_loglevel(?MODULE, error), lager:set_loglevel(?MODULE, error),
?assertEqual({?ERROR bor ?CRITICAL bor ?ALERT bor ?EMERGENCY, []}, lager_config:get(loglevel)),
sync_error_logger:info_report([hello, world]), sync_error_logger:info_report([hello, world]),
_ = gen_event:which_handlers(error_logger), _ = gen_event:which_handlers(error_logger),
?assertEqual(0, count()), ?assertEqual(0, count()),
?assertEqual(0, count_ignored()), ?assertEqual(0, count_ignored()),
lager:set_loglevel(?MODULE, info), lager:set_loglevel(?MODULE, info),
?assertEqual({?INFO bor ?NOTICE bor ?WARNING bor ?ERROR bor ?CRITICAL bor ?ALERT bor ?EMERGENCY, []}, lager_config:get(loglevel)),
sync_error_logger:info_report([hello, world]), sync_error_logger:info_report([hello, world]),
_ = gen_event:which_handlers(error_logger), _ = gen_event:which_handlers(error_logger),
?assertEqual(1, count()), ?assertEqual(1, count()),
?assertEqual(0, count_ignored()), ?assertEqual(0, count_ignored()),
lager:set_loglevel(?MODULE, error), lager:set_loglevel(?MODULE, error),
?assertEqual({?ERROR bor ?CRITICAL bor ?ALERT bor ?EMERGENCY, []}, lager_config:get(loglevel)),
lager_config:set(loglevel, {element(2, lager_util:config_to_mask(debug)), []}), lager_config:set(loglevel, {element(2, lager_util:config_to_mask(debug)), []}),
sync_error_logger:info_report([hello, world]), sync_error_logger:info_report([hello, world]),
_ = gen_event:which_handlers(error_logger), _ = gen_event:which_handlers(error_logger),

正在加载...
取消
保存