http_SUITE.erl 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. %% Copyright (c) 2018, 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(http_SUITE).
  15. -compile(export_all).
  16. -compile(nowarn_export_all).
  17. -import(ct_helper, [config/2]).
  18. -import(ct_helper, [doc/1]).
  19. -import(cowboy_test, [gun_open/1]).
  20. all() -> [{group, clear}].
  21. groups() -> [{clear, [parallel], ct_helper:all(?MODULE)}].
  22. init_routes(_) -> [
  23. {"localhost", [
  24. {"/", hello_h, []}
  25. ]}
  26. ].
  27. switch_protocol_flush(Config) ->
  28. doc("Confirm that switch_protocol does not flush unrelated messages."),
  29. ProtoOpts = #{
  30. env => #{dispatch => cowboy_router:compile(init_routes(Config))},
  31. stream_handlers => [switch_protocol_flush_h]
  32. },
  33. {ok, _} = cowboy:start_clear(switch_protocol_flush, [{port, 0}], ProtoOpts),
  34. Port = ranch:get_port(switch_protocol_flush),
  35. Self = self(),
  36. ConnPid = gun_open([{port, Port}, {type, tcp}, {protocol, http}|Config]),
  37. _ = gun:get(ConnPid, "/", [
  38. {<<"x-test-pid">>, pid_to_list(Self)}
  39. ]),
  40. receive
  41. {Self, Events} ->
  42. switch_protocol_flush_h:validate(Events)
  43. end.