http_SUITE.erl 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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(ct_helper, [get_remote_pid_tcp/1]).
  20. -import(ct_helper, [name/0]).
  21. -import(cowboy_test, [gun_open/1]).
  22. all() -> [{group, clear}].
  23. groups() -> [{clear, [parallel], ct_helper:all(?MODULE)}].
  24. init_routes(_) -> [
  25. {"localhost", [
  26. {"/", hello_h, []},
  27. {"/echo/:key", echo_h, []}
  28. ]}
  29. ].
  30. idle_timeout_infinity(Config) ->
  31. doc("Ensure the idle_timeout option accepts the infinity value."),
  32. {ok, _} = cowboy:start_clear(name(), [{port, 0}], #{
  33. env => #{dispatch => cowboy_router:compile(init_routes(Config))},
  34. request_timeout => infinity
  35. }),
  36. Port = ranch:get_port(name()),
  37. ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
  38. _ = gun:post(ConnPid, "/echo/read_body", [], <<"TEST">>),
  39. #{socket := Socket} = gun:info(ConnPid),
  40. Pid = get_remote_pid_tcp(Socket),
  41. Ref = erlang:monitor(process, Pid),
  42. receive
  43. {'DOWN', Ref, process, Pid, Reason} ->
  44. error(Reason)
  45. after 1000 ->
  46. ok
  47. end.
  48. request_timeout_infinity(Config) ->
  49. doc("Ensure the request_timeout option accepts the infinity value."),
  50. {ok, _} = cowboy:start_clear(name(), [{port, 0}], #{
  51. env => #{dispatch => cowboy_router:compile(init_routes(Config))},
  52. idle_timeout => infinity
  53. }),
  54. Port = ranch:get_port(name()),
  55. ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
  56. #{socket := Socket} = gun:info(ConnPid),
  57. Pid = get_remote_pid_tcp(Socket),
  58. Ref = erlang:monitor(process, Pid),
  59. receive
  60. {'DOWN', Ref, process, Pid, Reason} ->
  61. error(Reason)
  62. after 1000 ->
  63. ok
  64. end.
  65. switch_protocol_flush(Config) ->
  66. doc("Confirm that switch_protocol does not flush unrelated messages."),
  67. ProtoOpts = #{
  68. env => #{dispatch => cowboy_router:compile(init_routes(Config))},
  69. stream_handlers => [switch_protocol_flush_h]
  70. },
  71. {ok, _} = cowboy:start_clear(switch_protocol_flush, [{port, 0}], ProtoOpts),
  72. Port = ranch:get_port(switch_protocol_flush),
  73. Self = self(),
  74. ConnPid = gun_open([{port, Port}, {type, tcp}, {protocol, http}|Config]),
  75. _ = gun:get(ConnPid, "/", [
  76. {<<"x-test-pid">>, pid_to_list(Self)}
  77. ]),
  78. receive
  79. {Self, Events} ->
  80. switch_protocol_flush_h:validate(Events)
  81. end.