diff options
author | Loïc Hoguin <[email protected]> | 2020-06-08 15:46:42 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2020-06-18 15:06:51 +0200 |
commit | 39828681c7dae5c96e8d6ccf6411802a9b1fb470 (patch) | |
tree | c2dacd1dbbffc6207933f4523534e5eb261cb523 /test/ranch_concuerror.erl | |
parent | 9d16b30eefa47b6e8a477238319d9223f4438c40 (diff) | |
download | ranch-39828681c7dae5c96e8d6ccf6411802a9b1fb470.tar.gz ranch-39828681c7dae5c96e8d6ccf6411802a9b1fb470.tar.bz2 ranch-39828681c7dae5c96e8d6ccf6411802a9b1fb470.zip |
Add two Concuerror tests
The tests are starting and stopping a Ranch listener,
and starting a Ranch listener then immediately call
ranch:info/1.
Diffstat (limited to 'test/ranch_concuerror.erl')
-rw-r--r-- | test/ranch_concuerror.erl | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/test/ranch_concuerror.erl b/test/ranch_concuerror.erl new file mode 100644 index 0000000..0347fce --- /dev/null +++ b/test/ranch_concuerror.erl @@ -0,0 +1,80 @@ +%% Copyright (c) 2020, Loïc Hoguin <[email protected]> +%% +%% Permission to use, copy, modify, and/or distribute this software for any +%% purpose with or without fee is hereby granted, provided that the above +%% copyright notice and this permission notice appear in all copies. +%% +%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +-module(ranch_concuerror). +-compile(export_all). +-compile(nowarn_export_all). + +-concuerror_options([ + {after_timeout, 5000}, + {treat_as_normal, [ + killed, %% Acceptors are killed on shutdown. + shutdown %% This is a normal exit reason in OTP. + ]} +]). + +%% Convenience functions. + +do_start() -> + {ok, SupPid} = ranch_app:start(temporary, []), + SupPid. + +do_stop(SupPid) -> + exit(SupPid, shutdown), + %% We make sure that SupPid terminated before the test ends, + %% because otherwise the shutdown will not be ordered and + %% can produce error exit reasons. + receive after infinity -> ok end. + +%% Tests. + +start_stop() -> + %% Start a listener then stop it. + SupPid = do_start(), + {ok, _} = ranch:start_listener(?FUNCTION_NAME, + ranch_erlang_transport, #{ + num_acceptors => 1 + }, + echo_protocol, []), + ok = ranch:stop_listener(?FUNCTION_NAME), + do_stop(SupPid). + +%% @todo This takes a huge amount of time. +%start_stop_twice() -> +% %% Start a listener then stop it. Then start and stop it again. +% SupPid = do_start(), +% {ok, _} = ranch:start_listener(?FUNCTION_NAME, +% ranch_erlang_transport, #{ +% num_acceptors => 1 +% }, +% echo_protocol, []), +% ok = ranch:stop_listener(?FUNCTION_NAME), +% {ok, _} = ranch:start_listener(?FUNCTION_NAME, +% ranch_erlang_transport, #{ +% num_acceptors => 1 +% }, +% echo_protocol, []), +% ok = ranch:stop_listener(?FUNCTION_NAME), +% do_stop(SupPid). + +info() -> + %% Ensure we can call ranch:info/1 after starting a listener. + SupPid = do_start(), + {ok, _} = ranch:start_listener(?FUNCTION_NAME, + ranch_erlang_transport, #{ + num_acceptors => 1 + }, + echo_protocol, []), + #{} = ranch:info(?FUNCTION_NAME), + do_stop(SupPid). |