mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Explicitly close the socket in some tests for speed ups
The socket staying open meant that the graceful shut down of the Cowboy listeners were waiting for the connections to be closed gracefully (or a timeout). Closing explicitly where it makes sense ensures we don't unnecessarily wait. This commit removes a full minute in the run time of all Cowboy test suites (minus examples).
This commit is contained in:
parent
2558ba65ad
commit
627a4508b5
5 changed files with 51 additions and 21 deletions
|
@ -246,7 +246,7 @@ idle_timeout_infinity(Config) ->
|
|||
{'DOWN', Ref, process, Pid, Reason} ->
|
||||
error(Reason)
|
||||
after 1000 ->
|
||||
ok
|
||||
gun:close(ConnPid)
|
||||
end
|
||||
after
|
||||
cowboy:stop_listener(?FUNCTION_NAME)
|
||||
|
@ -293,7 +293,7 @@ request_timeout_infinity(Config) ->
|
|||
{'DOWN', Ref, process, Pid, Reason} ->
|
||||
error(Reason)
|
||||
after 1000 ->
|
||||
ok
|
||||
gun:close(ConnPid)
|
||||
end
|
||||
after
|
||||
cowboy:stop_listener(?FUNCTION_NAME)
|
||||
|
@ -349,7 +349,8 @@ set_options_chunked_false_ignored(Config) ->
|
|||
%% is not disabled for that second request.
|
||||
StreamRef2 = gun:get(ConnPid, "/resp/stream_reply2/200"),
|
||||
{response, nofin, 200, Headers} = gun:await(ConnPid, StreamRef2),
|
||||
{_, <<"chunked">>} = lists:keyfind(<<"transfer-encoding">>, 1, Headers)
|
||||
{_, <<"chunked">>} = lists:keyfind(<<"transfer-encoding">>, 1, Headers),
|
||||
gun:close(ConnPid)
|
||||
after
|
||||
cowboy:stop_listener(?FUNCTION_NAME)
|
||||
end.
|
||||
|
@ -492,6 +493,10 @@ graceful_shutdown_connection(Config) ->
|
|||
|
||||
graceful_shutdown_listener(Config) ->
|
||||
doc("Check that connections are shut down gracefully when stopping a listener."),
|
||||
TransOpts = #{
|
||||
socket_opts => [{port, 0}],
|
||||
shutdown => 1000 %% Shorter timeout to make the test case faster.
|
||||
},
|
||||
Dispatch = cowboy_router:compile([{"localhost", [
|
||||
{"/delay_hello", delay_hello_h,
|
||||
#{delay => 500, notify_received => self()}},
|
||||
|
@ -501,7 +506,7 @@ graceful_shutdown_listener(Config) ->
|
|||
ProtoOpts = #{
|
||||
env => #{dispatch => Dispatch}
|
||||
},
|
||||
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
||||
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, TransOpts, ProtoOpts),
|
||||
Port = ranch:get_port(?FUNCTION_NAME),
|
||||
ConnPid1 = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
||||
Ref1 = gun:get(ConnPid1, "/delay_hello"),
|
||||
|
@ -510,6 +515,8 @@ graceful_shutdown_listener(Config) ->
|
|||
%% Shutdown listener while the handlers are working.
|
||||
receive {request_received, <<"/delay_hello">>} -> ok end,
|
||||
receive {request_received, <<"/long_delay_hello">>} -> ok end,
|
||||
%% Note: This call does not complete quickly and will
|
||||
%% prevent other cowboy:stop_listener/1 calls to complete.
|
||||
ok = cowboy:stop_listener(?FUNCTION_NAME),
|
||||
%% Check that the 1st request is handled before shutting down.
|
||||
{response, nofin, 200, RespHeaders} = gun:await(ConnPid1, Ref1),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue