havoc_SUITE.erl 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. %% Copyright (c) 2019, Loïc Hoguin <essen@ninenines.eu>
  2. %%
  3. %% Permission to use, copy, modify, and/or distribute this software for any
  4. %% purpose with or without fee is hereby granted, provided that the above
  5. %% copyright notice and this permission notice appear in all copies.
  6. %%
  7. %% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. %% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. %% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. %% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. %% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. %% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. %% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. -module(havoc_SUITE).
  15. -compile(export_all).
  16. -compile(nowarn_export_all).
  17. -import(ct_helper, [doc/1]).
  18. -import(ct_helper, [name/0]).
  19. %% ct.
  20. all() ->
  21. ct_helper:all(?MODULE).
  22. init_per_suite(Config) ->
  23. {ok, _} = application:ensure_all_started(ranch),
  24. ok = application:start(havoc),
  25. %% Comment to hide progress reports in the terminal.
  26. application:set_env(kernel, logger_sasl_compatible, true),
  27. ok = application:start(sasl),
  28. %% Enable logging of progress reports.
  29. %% They will only be available in the HTML reports by default.
  30. ok = logger:set_primary_config(level, info),
  31. Config.
  32. end_per_suite(_) ->
  33. ok = application:stop(sasl),
  34. ok = application:stop(havoc),
  35. ok = application:stop(ranch).
  36. %% Tests.
  37. havoc_tcp(_) ->
  38. doc("Start a TCP listener, establish a hundred connections, "
  39. "run havoc, confirm we can still connect."),
  40. %% Start a TCP listener.
  41. Name = name(),
  42. {ok, _} = ranch:start_listener(Name,
  43. ranch_tcp, #{},
  44. echo_protocol, []),
  45. Port = ranch:get_port(Name),
  46. %% Establish a hundred connections.
  47. _ = [begin
  48. {ok, Socket} = gen_tcp:connect("localhost", Port, [{active, false}]),
  49. Socket
  50. end || _ <- lists:seq(1, 100)],
  51. %% Run Havoc.
  52. havoc:on([{applications, [ranch]}]),
  53. timer:sleep(60000),
  54. havoc:off(),
  55. timer:sleep(1000),
  56. %% Confirm we can still connect.
  57. {ok, _} = gen_tcp:connect("localhost", Port, [{active, false}]),
  58. ok = ranch:stop_listener(Name).