aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJan Uhlig <[email protected]>2021-09-01 12:30:33 +0200
committerJan Uhlig <[email protected]>2021-09-01 12:30:33 +0200
commit4687f74954c1392da30c00f6031a2c99a2933834 (patch)
treeb870e202b480b5c8e6ca12f42bb7a1ea02d0a8d3 /test
parent18816dfb0c3e01467855c0061023548db1655453 (diff)
downloadranch-4687f74954c1392da30c00f6031a2c99a2933834.tar.gz
ranch-4687f74954c1392da30c00f6031a2c99a2933834.tar.bz2
ranch-4687f74954c1392da30c00f6031a2c99a2933834.zip
Add post-listen callback
Diffstat (limited to 'test')
-rw-r--r--test/acceptor_SUITE.erl43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/acceptor_SUITE.erl b/test/acceptor_SUITE.erl
index 6ca9bd3..1028614 100644
--- a/test/acceptor_SUITE.erl
+++ b/test/acceptor_SUITE.erl
@@ -77,6 +77,8 @@ groups() ->
misc_info_embedded,
misc_metrics,
misc_opts_logger,
+ misc_post_listen_callback,
+ misc_post_listen_callback_error,
misc_set_transport_options,
misc_wait_for_connections,
misc_multiple_ip_local_socket_opts
@@ -340,6 +342,47 @@ misc_opts_logger(_) ->
warning(Format, Args) ->
misc_opts_logger ! {warning, Format, Args}.
+misc_post_listen_callback(_) ->
+ doc("Ensure that the post-listen callback works."),
+ Name = name(),
+ Self = self(),
+ Ref = make_ref(),
+ PostListenCb = fun (LSock) ->
+ ok = ranch_tcp:setopts(LSock, [{send_timeout, 1000}]),
+ Self ! {post_listen, Ref, LSock},
+ ok
+ end,
+ {ok, _} = ranch:start_listener(Name,
+ ranch_tcp, #{post_listen_callback => PostListenCb,
+ socket_opts => [{send_timeout, infinity}]},
+ echo_protocol, []),
+ receive
+ {post_listen, Ref, LSock} ->
+ {ok, [{send_timeout, 1000}]} = ranch_tcp:getopts(LSock, [send_timeout]),
+ ok
+ after 1000 ->
+ error(timeout)
+ end,
+ Port = ranch:get_port(Name),
+ {ok, S} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]),
+ ok = gen_tcp:send(S, <<"Test">>),
+ {ok, <<"Test">>} = gen_tcp:recv(S, 4, 1000),
+ ok = ranch:stop_listener(Name),
+ {error, closed} = gen_tcp:recv(S, 0, 1000),
+ %% Make sure the listener stopped.
+ {'EXIT', _} = begin catch ranch:get_port(Name) end,
+ ok.
+
+misc_post_listen_callback_error(_) ->
+ doc("Ensure that starting a listener fails when the post-listen callback returns an error."),
+ Name = name(),
+ PostListenCb = fun (_) -> {error, test} end,
+ {error, _} = ranch:start_listener(Name,
+ ranch_tcp, #{post_listen_callback => PostListenCb},
+ echo_protocol, []),
+ {'EXIT', _} = begin catch ranch:get_port(Name) end,
+ ok.
+
misc_repeated_remove(_) ->
doc("Ensure repeated removal of connection does not crash the connection supervisor."),
Name = name(),