acceptor_SUITE.erl 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. %% Copyright (c) 2011-2012, 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(acceptor_SUITE).
  15. -include_lib("common_test/include/ct.hrl").
  16. -export([all/0, groups/0, init_per_suite/1, end_per_suite/1]). %% ct.
  17. -export([tcp_echo/1]). %% tcp.
  18. %% ct.
  19. all() ->
  20. [{group, tcp}].
  21. groups() ->
  22. Tests = [tcp_echo],
  23. [{tcp, Tests}].
  24. init_per_suite(Config) ->
  25. application:start(ranch),
  26. Config.
  27. end_per_suite(_) ->
  28. application:stop(ranch),
  29. ok.
  30. %% tcp.
  31. tcp_echo(_) ->
  32. %% @todo Don't use a fixed port. start_listener should return the port used?
  33. {ok, _} = ranch:start_listener(tcp_echo, 1,
  34. ranch_tcp, [{port, 33333}],
  35. echo_protocol, []),
  36. {ok, Socket} = gen_tcp:connect("localhost", 33333,
  37. [binary, {active, false}, {packet, raw}]),
  38. ok = gen_tcp:send(Socket, <<"Ranch is working!">>),
  39. {ok, <<"Ranch is working!">>} = gen_tcp:recv(Socket, 0, 1000),
  40. ok = ranch:stop_listener(tcp_echo),
  41. {error, closed} = gen_tcp:recv(Socket, 0, 1000),
  42. ok.