0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Use infinity timeout for gun:await* calls in req_SUITE

This commit is contained in:
Loïc Hoguin 2020-04-02 14:57:10 +02:00
parent 789768e8d3
commit 0143d9e5a9
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764

View file

@ -78,9 +78,9 @@ do_body(Method, Path, Headers0, Body, Config) ->
ConnPid = gun_open(Config), ConnPid = gun_open(Config),
Headers = [{<<"accept-encoding">>, <<"gzip">>}|Headers0], Headers = [{<<"accept-encoding">>, <<"gzip">>}|Headers0],
Ref = gun:request(ConnPid, Method, Path, Headers, Body), Ref = gun:request(ConnPid, Method, Path, Headers, Body),
{response, IsFin, 200, RespHeaders} = gun:await(ConnPid, Ref, 10000), {response, IsFin, 200, RespHeaders} = gun:await(ConnPid, Ref, infinity),
{ok, RespBody} = case IsFin of {ok, RespBody} = case IsFin of
nofin -> gun:await_body(ConnPid, Ref); nofin -> gun:await_body(ConnPid, Ref, infinity);
fin -> {ok, <<>>} fin -> {ok, <<>>}
end, end,
gun:close(ConnPid), gun:close(ConnPid),
@ -90,7 +90,7 @@ do_body_error(Method, Path, Headers0, Body, Config) ->
ConnPid = gun_open(Config), ConnPid = gun_open(Config),
Headers = [{<<"accept-encoding">>, <<"gzip">>}|Headers0], Headers = [{<<"accept-encoding">>, <<"gzip">>}|Headers0],
Ref = gun:request(ConnPid, Method, Path, Headers, Body), Ref = gun:request(ConnPid, Method, Path, Headers, Body),
{response, _, Status, RespHeaders} = gun:await(ConnPid, Ref), {response, _, Status, RespHeaders} = gun:await(ConnPid, Ref, infinity),
gun:close(ConnPid), gun:close(ConnPid),
{Status, RespHeaders}. {Status, RespHeaders}.
@ -100,9 +100,9 @@ do_get(Path, Config) ->
do_get(Path, Headers, Config) -> do_get(Path, Headers, Config) ->
ConnPid = gun_open(Config), ConnPid = gun_open(Config),
Ref = gun:get(ConnPid, Path, [{<<"accept-encoding">>, <<"gzip">>}|Headers]), Ref = gun:get(ConnPid, Path, [{<<"accept-encoding">>, <<"gzip">>}|Headers]),
{response, IsFin, Status, RespHeaders} = gun:await(ConnPid, Ref), {response, IsFin, Status, RespHeaders} = gun:await(ConnPid, Ref, infinity),
{ok, RespBody} = case IsFin of {ok, RespBody} = case IsFin of
nofin -> gun:await_body(ConnPid, Ref, 30000); nofin -> gun:await_body(ConnPid, Ref, infinity);
fin -> {ok, <<>>} fin -> {ok, <<>>}
end, end,
gun:close(ConnPid), gun:close(ConnPid),
@ -117,21 +117,21 @@ do_get_body(Path, Headers, Config) ->
do_get_inform(Path, Config) -> do_get_inform(Path, Config) ->
ConnPid = gun_open(Config), ConnPid = gun_open(Config),
Ref = gun:get(ConnPid, Path, [{<<"accept-encoding">>, <<"gzip">>}]), Ref = gun:get(ConnPid, Path, [{<<"accept-encoding">>, <<"gzip">>}]),
case gun:await(ConnPid, Ref) of case gun:await(ConnPid, Ref, infinity) of
{response, _, RespStatus, RespHeaders} -> {response, _, RespStatus, RespHeaders} ->
%% We don't care about the body. %% We don't care about the body.
gun:close(ConnPid), gun:close(ConnPid),
{RespStatus, RespHeaders}; {RespStatus, RespHeaders};
{inform, InfoStatus, InfoHeaders} -> {inform, InfoStatus, InfoHeaders} ->
{response, IsFin, RespStatus, RespHeaders} {response, IsFin, RespStatus, RespHeaders}
= case gun:await(ConnPid, Ref) of = case gun:await(ConnPid, Ref, infinity) of
{inform, InfoStatus, InfoHeaders} -> {inform, InfoStatus, InfoHeaders} ->
gun:await(ConnPid, Ref); gun:await(ConnPid, Ref, infinity);
Response -> Response ->
Response Response
end, end,
{ok, RespBody} = case IsFin of {ok, RespBody} = case IsFin of
nofin -> gun:await_body(ConnPid, Ref); nofin -> gun:await_body(ConnPid, Ref, infinity);
fin -> {ok, <<>>} fin -> {ok, <<>>}
end, end,
gun:close(ConnPid), gun:close(ConnPid),
@ -150,9 +150,9 @@ do_get_error(Path, Config) ->
do_get_error(Path, Headers, Config) -> do_get_error(Path, Headers, Config) ->
ConnPid = gun_open(Config), ConnPid = gun_open(Config),
Ref = gun:get(ConnPid, Path, [{<<"accept-encoding">>, <<"gzip">>}|Headers]), Ref = gun:get(ConnPid, Path, [{<<"accept-encoding">>, <<"gzip">>}|Headers]),
{response, IsFin, Status, RespHeaders} = gun:await(ConnPid, Ref), {response, IsFin, Status, RespHeaders} = gun:await(ConnPid, Ref, infinity),
Result = case IsFin of Result = case IsFin of
nofin -> gun:await_body(ConnPid, Ref); nofin -> gun:await_body(ConnPid, Ref, infinity);
fin -> {ok, <<>>} fin -> {ok, <<>>}
end, end,
case Result of case Result of
@ -500,8 +500,8 @@ read_body_period(Config) ->
%% for 2 seconds. The test succeeds if we get some of the data back %% for 2 seconds. The test succeeds if we get some of the data back
%% (meaning the function will have returned after the period ends). %% (meaning the function will have returned after the period ends).
gun:data(ConnPid, Ref, nofin, Body), gun:data(ConnPid, Ref, nofin, Body),
{response, nofin, 200, _} = gun:await(ConnPid, Ref), {response, nofin, 200, _} = gun:await(ConnPid, Ref, infinity),
{data, _, Data} = gun:await(ConnPid, Ref), {data, _, Data} = gun:await(ConnPid, Ref, infinity),
%% We expect to read at least some data. %% We expect to read at least some data.
true = Data =/= <<>>, true = Data =/= <<>>,
gun:close(ConnPid). gun:close(ConnPid).
@ -512,7 +512,7 @@ do_read_body_timeout(Path, Body, Config) ->
Ref = gun:headers(ConnPid, "POST", Path, [ Ref = gun:headers(ConnPid, "POST", Path, [
{<<"content-length">>, integer_to_binary(byte_size(Body))} {<<"content-length">>, integer_to_binary(byte_size(Body))}
]), ]),
{response, _, 500, _} = gun:await(ConnPid, Ref), {response, _, 500, _} = gun:await(ConnPid, Ref, infinity),
gun:close(ConnPid). gun:close(ConnPid).
read_body_spawn(Config) -> read_body_spawn(Config) ->
@ -572,7 +572,7 @@ do_read_urlencoded_body_too_large(Path, Body, Config) ->
{<<"content-length">>, integer_to_binary(iolist_size(Body))} {<<"content-length">>, integer_to_binary(iolist_size(Body))}
]), ]),
gun:data(ConnPid, Ref, fin, Body), gun:data(ConnPid, Ref, fin, Body),
{response, _, 413, _} = gun:await(ConnPid, Ref), {response, _, 413, _} = gun:await(ConnPid, Ref, infinity),
gun:close(ConnPid). gun:close(ConnPid).
read_urlencoded_body_too_long(Config) -> read_urlencoded_body_too_long(Config) ->
@ -590,7 +590,7 @@ do_read_urlencoded_body_too_long(Path, Body, Config) ->
gun:data(ConnPid, Ref, nofin, Body), gun:data(ConnPid, Ref, nofin, Body),
timer:sleep(2000), timer:sleep(2000),
gun:data(ConnPid, Ref, fin, Body), gun:data(ConnPid, Ref, fin, Body),
{response, _, 408, RespHeaders} = gun:await(ConnPid, Ref), {response, _, 408, RespHeaders} = gun:await(ConnPid, Ref, infinity),
_ = case config(protocol, Config) of _ = case config(protocol, Config) of
http -> http ->
%% 408 error responses should close HTTP/1.1 connections. %% 408 error responses should close HTTP/1.1 connections.
@ -820,16 +820,16 @@ set_resp_body_sendfile0(Config) ->
ConnPid = gun_open(Config), ConnPid = gun_open(Config),
%% First request. %% First request.
Ref1 = gun:get(ConnPid, Path, [{<<"accept-encoding">>, <<"gzip">>}]), Ref1 = gun:get(ConnPid, Path, [{<<"accept-encoding">>, <<"gzip">>}]),
{response, IsFin, 200, _} = gun:await(ConnPid, Ref1), {response, IsFin, 200, _} = gun:await(ConnPid, Ref1, infinity),
{ok, <<>>} = case IsFin of {ok, <<>>} = case IsFin of
nofin -> gun:await_body(ConnPid, Ref1); nofin -> gun:await_body(ConnPid, Ref1, infinity);
fin -> {ok, <<>>} fin -> {ok, <<>>}
end, end,
%% Second request will confirm everything works as intended. %% Second request will confirm everything works as intended.
Ref2 = gun:get(ConnPid, Path, [{<<"accept-encoding">>, <<"gzip">>}]), Ref2 = gun:get(ConnPid, Path, [{<<"accept-encoding">>, <<"gzip">>}]),
{response, IsFin, 200, _} = gun:await(ConnPid, Ref2), {response, IsFin, 200, _} = gun:await(ConnPid, Ref2, infinity),
{ok, <<>>} = case IsFin of {ok, <<>>} = case IsFin of
nofin -> gun:await_body(ConnPid, Ref2); nofin -> gun:await_body(ConnPid, Ref2, infinity);
fin -> {ok, <<>>} fin -> {ok, <<>>}
end, end,
gun:close(ConnPid), gun:close(ConnPid),
@ -1085,10 +1085,10 @@ stream_trailers_no_te(Config) ->
Ref = gun:get(ConnPid, "/resp/stream_trailers", [ Ref = gun:get(ConnPid, "/resp/stream_trailers", [
{<<"accept-encoding">>, <<"gzip">>} {<<"accept-encoding">>, <<"gzip">>}
]), ]),
{response, nofin, 200, RespHeaders} = gun:await(ConnPid, Ref), {response, nofin, 200, RespHeaders} = gun:await(ConnPid, Ref, infinity),
%% @todo Do we want to remove the trailer header automatically? %% @todo Do we want to remove the trailer header automatically?
% false = lists:keyfind(<<"trailer">>, 1, RespHeaders), % false = lists:keyfind(<<"trailer">>, 1, RespHeaders),
{ok, RespBody} = gun:await_body(ConnPid, Ref), {ok, RespBody} = gun:await_body(ConnPid, Ref, infinity),
<<"Hello world!">> = do_decode(RespHeaders, RespBody), <<"Hello world!">> = do_decode(RespHeaders, RespBody),
gun:close(ConnPid). gun:close(ConnPid).
@ -1098,8 +1098,8 @@ do_trailers(Path, Config) ->
{<<"accept-encoding">>, <<"gzip">>}, {<<"accept-encoding">>, <<"gzip">>},
{<<"te">>, <<"trailers">>} {<<"te">>, <<"trailers">>}
]), ]),
{response, nofin, Status, RespHeaders} = gun:await(ConnPid, Ref), {response, nofin, Status, RespHeaders} = gun:await(ConnPid, Ref, infinity),
{ok, RespBody, Trailers} = gun:await_body(ConnPid, Ref), {ok, RespBody, Trailers} = gun:await_body(ConnPid, Ref, infinity),
gun:close(ConnPid), gun:close(ConnPid),
{Status, RespHeaders, do_decode(RespHeaders, RespBody), Trailers}. {Status, RespHeaders, do_decode(RespHeaders, RespBody), Trailers}.
@ -1141,7 +1141,7 @@ do_push_http(Path, Config) ->
doc("Ignore pushed responses when protocol is HTTP/1.1."), doc("Ignore pushed responses when protocol is HTTP/1.1."),
ConnPid = gun_open(Config), ConnPid = gun_open(Config),
Ref = gun:get(ConnPid, Path, []), Ref = gun:get(ConnPid, Path, []),
{response, fin, 200, _} = gun:await(ConnPid, Ref), {response, fin, 200, _} = gun:await(ConnPid, Ref, infinity),
ok. ok.
do_push_http2(Config) -> do_push_http2(Config) ->
@ -1159,17 +1159,17 @@ do_push_http2(Config) ->
]), ]),
OriginLen = byte_size(Origin), OriginLen = byte_size(Origin),
{push, PushCSS, <<"GET">>, <<Origin:OriginLen/binary, "/static/style.css">>, {push, PushCSS, <<"GET">>, <<Origin:OriginLen/binary, "/static/style.css">>,
[{<<"accept">>,<<"text/css">>}]} = gun:await(ConnPid, Ref), [{<<"accept">>,<<"text/css">>}]} = gun:await(ConnPid, Ref, infinity),
{push, PushTXT, <<"GET">>, <<Origin:OriginLen/binary, "/static/plain.txt">>, {push, PushTXT, <<"GET">>, <<Origin:OriginLen/binary, "/static/plain.txt">>,
[{<<"accept">>,<<"text/plain">>}]} = gun:await(ConnPid, Ref), [{<<"accept">>,<<"text/plain">>}]} = gun:await(ConnPid, Ref, infinity),
%% Pushed CSS. %% Pushed CSS.
{response, nofin, 200, HeadersCSS} = gun:await(ConnPid, PushCSS), {response, nofin, 200, HeadersCSS} = gun:await(ConnPid, PushCSS, infinity),
{_, <<"text/css">>} = lists:keyfind(<<"content-type">>, 1, HeadersCSS), {_, <<"text/css">>} = lists:keyfind(<<"content-type">>, 1, HeadersCSS),
{ok, <<"body{color:red}\n">>} = gun:await_body(ConnPid, PushCSS), {ok, <<"body{color:red}\n">>} = gun:await_body(ConnPid, PushCSS, infinity),
%% Pushed TXT is 406 because the pushed accept header uses an undefined type. %% Pushed TXT is 406 because the pushed accept header uses an undefined type.
{response, fin, 406, _} = gun:await(ConnPid, PushTXT), {response, fin, 406, _} = gun:await(ConnPid, PushTXT, infinity),
%% Let's not forget about the response to the client's request. %% Let's not forget about the response to the client's request.
{response, fin, 200, _} = gun:await(ConnPid, Ref), {response, fin, 200, _} = gun:await(ConnPid, Ref, infinity),
gun:close(ConnPid). gun:close(ConnPid).
do_push_http2_method(Config) -> do_push_http2_method(Config) ->
@ -1177,11 +1177,11 @@ do_push_http2_method(Config) ->
ConnPid = gun_open(Config), ConnPid = gun_open(Config),
Ref = gun:get(ConnPid, "/resp/push/method", []), Ref = gun:get(ConnPid, "/resp/push/method", []),
%% Pushed CSS. %% Pushed CSS.
{push, PushCSS, <<"HEAD">>, _, [{<<"accept">>,<<"text/css">>}]} = gun:await(ConnPid, Ref), {push, PushCSS, <<"HEAD">>, _, [{<<"accept">>,<<"text/css">>}]} = gun:await(ConnPid, Ref, infinity),
{response, fin, 200, HeadersCSS} = gun:await(ConnPid, PushCSS), {response, fin, 200, HeadersCSS} = gun:await(ConnPid, PushCSS, infinity),
{_, <<"text/css">>} = lists:keyfind(<<"content-type">>, 1, HeadersCSS), {_, <<"text/css">>} = lists:keyfind(<<"content-type">>, 1, HeadersCSS),
%% Let's not forget about the response to the client's request. %% Let's not forget about the response to the client's request.
{response, fin, 200, _} = gun:await(ConnPid, Ref), {response, fin, 200, _} = gun:await(ConnPid, Ref, infinity),
gun:close(ConnPid). gun:close(ConnPid).
do_push_http2_origin(Config) -> do_push_http2_origin(Config) ->
@ -1190,12 +1190,12 @@ do_push_http2_origin(Config) ->
Ref = gun:get(ConnPid, "/resp/push/origin", []), Ref = gun:get(ConnPid, "/resp/push/origin", []),
%% Pushed CSS. %% Pushed CSS.
{push, PushCSS, <<"GET">>, <<"ftp://127.0.0.1:21/static/style.css">>, {push, PushCSS, <<"GET">>, <<"ftp://127.0.0.1:21/static/style.css">>,
[{<<"accept">>,<<"text/css">>}]} = gun:await(ConnPid, Ref), [{<<"accept">>,<<"text/css">>}]} = gun:await(ConnPid, Ref, infinity),
{response, nofin, 200, HeadersCSS} = gun:await(ConnPid, PushCSS), {response, nofin, 200, HeadersCSS} = gun:await(ConnPid, PushCSS, infinity),
{_, <<"text/css">>} = lists:keyfind(<<"content-type">>, 1, HeadersCSS), {_, <<"text/css">>} = lists:keyfind(<<"content-type">>, 1, HeadersCSS),
{ok, <<"body{color:red}\n">>} = gun:await_body(ConnPid, PushCSS), {ok, <<"body{color:red}\n">>} = gun:await_body(ConnPid, PushCSS, infinity),
%% Let's not forget about the response to the client's request. %% Let's not forget about the response to the client's request.
{response, fin, 200, _} = gun:await(ConnPid, Ref), {response, fin, 200, _} = gun:await(ConnPid, Ref, infinity),
gun:close(ConnPid). gun:close(ConnPid).
do_push_http2_qs(Config) -> do_push_http2_qs(Config) ->
@ -1213,10 +1213,10 @@ do_push_http2_qs(Config) ->
]), ]),
OriginLen = byte_size(Origin), OriginLen = byte_size(Origin),
{push, PushCSS, <<"GET">>, <<Origin:OriginLen/binary, "/static/style.css?server=cowboy&version=2.0">>, {push, PushCSS, <<"GET">>, <<Origin:OriginLen/binary, "/static/style.css?server=cowboy&version=2.0">>,
[{<<"accept">>,<<"text/css">>}]} = gun:await(ConnPid, Ref), [{<<"accept">>,<<"text/css">>}]} = gun:await(ConnPid, Ref, infinity),
{response, nofin, 200, HeadersCSS} = gun:await(ConnPid, PushCSS), {response, nofin, 200, HeadersCSS} = gun:await(ConnPid, PushCSS, infinity),
{_, <<"text/css">>} = lists:keyfind(<<"content-type">>, 1, HeadersCSS), {_, <<"text/css">>} = lists:keyfind(<<"content-type">>, 1, HeadersCSS),
{ok, <<"body{color:red}\n">>} = gun:await_body(ConnPid, PushCSS), {ok, <<"body{color:red}\n">>} = gun:await_body(ConnPid, PushCSS, infinity),
%% Let's not forget about the response to the client's request. %% Let's not forget about the response to the client's request.
{response, fin, 200, _} = gun:await(ConnPid, Ref), {response, fin, 200, _} = gun:await(ConnPid, Ref, infinity),
gun:close(ConnPid). gun:close(ConnPid).