aboutsummaryrefslogtreecommitdiffstats
path: root/test/gun_SUITE.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-01-10 10:36:51 +0100
committerLoïc Hoguin <[email protected]>2019-01-10 10:36:51 +0100
commit84fed6cb0b64bab858a084718185586c3656d1d4 (patch)
treec70dfd5b6ff63b56b848f51d2cb74d65543ba964 /test/gun_SUITE.erl
parent655adf004ec53a6f38375e3b0a53e485849f8a02 (diff)
downloadgun-84fed6cb0b64bab858a084718185586c3656d1d4.tar.gz
gun-84fed6cb0b64bab858a084718185586c3656d1d4.tar.bz2
gun-84fed6cb0b64bab858a084718185586c3656d1d4.zip
Tweak timeouts to fix intermittent failures
Diffstat (limited to 'test/gun_SUITE.erl')
-rw-r--r--test/gun_SUITE.erl123
1 files changed, 62 insertions, 61 deletions
diff --git a/test/gun_SUITE.erl b/test/gun_SUITE.erl
index acaee64..f4587e3 100644
--- a/test/gun_SUITE.erl
+++ b/test/gun_SUITE.erl
@@ -52,66 +52,6 @@ atom_hostname(_) ->
[<<"host: localhost:", _/bits>>] = [L || <<"host: ", _/bits>> = L <- Lines],
gun:close(Pid).
-stream_info_http(_) ->
- doc("Ensure the function gun:stream_info/2 works as expected for HTTP/1.1."),
- {ok, _, OriginPort} = init_origin(tcp, http,
- fun(_, ClientSocket, ClientTransport) ->
- %% Give some time to detect the cancel.
- timer:sleep(100),
- %% Then terminate the stream.
- ClientTransport:send(ClientSocket,
- "HTTP/1.1 200 OK\r\n"
- "content-length: 0\r\n"
- "\r\n"
- ),
- timer:sleep(200)
- end),
- {ok, Pid} = gun:open("localhost", OriginPort),
- {ok, http} = gun:await_up(Pid),
- {ok, undefined} = gun:stream_info(Pid, make_ref()),
- StreamRef = gun:get(Pid, "/"),
- Self = self(),
- {ok, #{
- ref := StreamRef,
- reply_to := Self,
- state := running
- }} = gun:stream_info(Pid, StreamRef),
- gun:cancel(Pid, StreamRef),
- {ok, #{
- ref := StreamRef,
- reply_to := Self,
- state := stopping
- }} = gun:stream_info(Pid, StreamRef),
- %% Wait a little for the stream to terminate.
- timer:sleep(200),
- {ok, undefined} = gun:stream_info(Pid, StreamRef),
- %% Wait a little more for the connection to terminate.
- timer:sleep(200),
- {error, not_connected} = gun:stream_info(Pid, StreamRef),
- gun:close(Pid).
-
-stream_info_http2(_) ->
- doc("Ensure the function gun:stream_info/2 works as expected for HTTP/2."),
- {ok, _, OriginPort} = init_origin(tcp, http2,
- fun(_, _, _) -> timer:sleep(100) end),
- {ok, Pid} = gun:open("localhost", OriginPort, #{
- protocols => [http2]
- }),
- {ok, http2} = gun:await_up(Pid),
- {ok, undefined} = gun:stream_info(Pid, make_ref()),
- StreamRef = gun:get(Pid, "/"),
- Self = self(),
- {ok, #{
- ref := StreamRef,
- reply_to := Self,
- state := running
- }} = gun:stream_info(Pid, StreamRef),
- gun:cancel(Pid, StreamRef),
- %% Wait a little for the connection to terminate.
- timer:sleep(200),
- {error, not_connected} = gun:stream_info(Pid, StreamRef),
- gun:close(Pid).
-
connect_timeout(_) ->
doc("Ensure an integer value for connect_timeout is accepted."),
{ok, Pid} = gun:open("localhost", 12345, #{connect_timeout => 1000, retry => 0}),
@@ -422,10 +362,71 @@ retry_timeout(_) ->
receive
{'DOWN', Ref, process, Pid, {shutdown, _}} ->
ok
- after 400 ->
+ after 800 ->
error(shutdown_too_late)
end.
+stream_info_http(_) ->
+ doc("Ensure the function gun:stream_info/2 works as expected for HTTP/1.1."),
+ {ok, _, OriginPort} = init_origin(tcp, http,
+ fun(_, ClientSocket, ClientTransport) ->
+ %% Give some time to detect the cancel.
+ timer:sleep(100),
+ %% Then terminate the stream.
+ ClientTransport:send(ClientSocket,
+ "HTTP/1.1 200 OK\r\n"
+ "content-length: 0\r\n"
+ "\r\n"
+ ),
+ timer:sleep(200)
+ end),
+ {ok, Pid} = gun:open("localhost", OriginPort),
+ {ok, http} = gun:await_up(Pid),
+ {ok, undefined} = gun:stream_info(Pid, make_ref()),
+ StreamRef = gun:get(Pid, "/"),
+ Self = self(),
+ {ok, #{
+ ref := StreamRef,
+ reply_to := Self,
+ state := running
+ }} = gun:stream_info(Pid, StreamRef),
+ gun:cancel(Pid, StreamRef),
+ {ok, #{
+ ref := StreamRef,
+ reply_to := Self,
+ state := stopping
+ }} = gun:stream_info(Pid, StreamRef),
+ %% Wait a little for the stream to terminate.
+ timer:sleep(200),
+ {ok, undefined} = gun:stream_info(Pid, StreamRef),
+ %% Wait a little more for the connection to terminate.
+ timer:sleep(200),
+ {error, not_connected} = gun:stream_info(Pid, StreamRef),
+ gun:close(Pid).
+
+stream_info_http2(_) ->
+ doc("Ensure the function gun:stream_info/2 works as expected for HTTP/2."),
+ {ok, _, OriginPort} = init_origin(tcp, http2,
+ fun(_, _, _) -> timer:sleep(100) end),
+ {ok, Pid} = gun:open("localhost", OriginPort, #{
+ protocols => [http2]
+ }),
+ {ok, http2} = gun:await_up(Pid),
+ timer:sleep(100), %% Give enough time for the handshake to fully complete.
+ {ok, undefined} = gun:stream_info(Pid, make_ref()),
+ StreamRef = gun:get(Pid, "/"),
+ Self = self(),
+ {ok, #{
+ ref := StreamRef,
+ reply_to := Self,
+ state := running
+ }} = gun:stream_info(Pid, StreamRef),
+ gun:cancel(Pid, StreamRef),
+ %% Wait a little for the connection to terminate.
+ timer:sleep(200),
+ {error, not_connected} = gun:stream_info(Pid, StreamRef),
+ gun:close(Pid).
+
shutdown_reason(_) ->
doc("The last connection failure must be propagated."),
{ok, Pid} = gun:open("localhost", 12345, #{retry => 0}),