You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 rivejä
2.6 KiB

  1. %% -------------------------------------------------------------------
  2. %%
  3. %% Copyright (c) 2011-2017 Basho Technologies, Inc.
  4. %%
  5. %% This file is provided to you under the Apache License,
  6. %% Version 2.0 (the "License"); you may not use this file
  7. %% except in compliance with the License. You may obtain
  8. %% a copy of the License at
  9. %%
  10. %% http://www.apache.org/licenses/LICENSE-2.0
  11. %%
  12. %% Unless required by applicable law or agreed to in writing,
  13. %% software distributed under the License is distributed on an
  14. %% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. %% KIND, either express or implied. See the License for the
  16. %% specific language governing permissions and limitations
  17. %% under the License.
  18. %%
  19. %% -------------------------------------------------------------------
  20. -module(lager_test_function_transform_error).
  21. -compile([
  22. {parse_transform, lager_transform}
  23. ]).
  24. -lager_function_transforms([
  25. {returns_undefined, {not_real_module_fake, fake_not_real_function}}
  26. ]).
  27. -ifdef(TEST).
  28. -include_lib("eunit/include/eunit.hrl").
  29. -endif.
  30. setup() ->
  31. error_logger:tty(false),
  32. application:load(lager),
  33. application:set_env(lager, handlers, [{lager_test_backend, info}]),
  34. application:set_env(lager, error_logger_redirect, false),
  35. application:unset_env(lager, traces),
  36. lager:start(),
  37. %% There is a race condition between the application start up, lager logging its own
  38. %% start up condition and several tests that count messages or parse the output of
  39. %% tests. When the lager start up message wins the race, it causes these tests
  40. %% which parse output or count message arrivals to fail.
  41. %%
  42. %% We introduce a sleep here to allow `flush' to arrive *after* the start up
  43. %% message has been received and processed.
  44. %%
  45. %% This race condition was first exposed during the work on
  46. %% 4b5260c4524688b545cc12da6baa2dfa4f2afec9 which introduced the lager
  47. %% manager killer PR.
  48. timer:sleep(5),
  49. gen_event:call(lager_event, lager_test_backend, flush).
  50. cleanup(_) ->
  51. catch ets:delete(lager_config), %% kill the ets config table with fire
  52. application:stop(lager),
  53. application:stop(goldrush),
  54. error_logger:tty(true).
  55. transform_function_error_test_() ->
  56. {foreach,
  57. fun setup/0,
  58. fun cleanup/1,
  59. [
  60. {"observe that there is nothing up my sleeve",
  61. fun() ->
  62. ?assertEqual(undefined, lager_test_backend:pop()),
  63. ?assertEqual(0, lager_test_backend:count())
  64. end
  65. },
  66. {"Testing a function transform for a undefined function errors",
  67. fun() ->
  68. ?assertError(undef, lager:warning("undefined message")),
  69. ok
  70. end
  71. }
  72. ]
  73. }.