diff options
author | Loïc Hoguin <[email protected]> | 2023-12-18 18:11:10 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2023-12-18 18:17:09 +0100 |
commit | 627a4508b539f98fb632b4ff9a92a4f9c2c54890 (patch) | |
tree | 5d99c4af8c423251675e54ac88b29ede4a0777f5 /test/http_SUITE.erl | |
parent | 2558ba65ad3e39dd10ab65196af8f4dbb067f476 (diff) | |
download | cowboy-627a4508b539f98fb632b4ff9a92a4f9c2c54890.tar.gz cowboy-627a4508b539f98fb632b4ff9a92a4f9c2c54890.tar.bz2 cowboy-627a4508b539f98fb632b4ff9a92a4f9c2c54890.zip |
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).
Diffstat (limited to 'test/http_SUITE.erl')
-rw-r--r-- | test/http_SUITE.erl | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl index 7f3373d..ccac04f 100644 --- a/test/http_SUITE.erl +++ b/test/http_SUITE.erl @@ -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), |