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

Get rid of timeouts in metrics_SUITE

Again to avoid intermittent issues.
This commit is contained in:
Loïc Hoguin 2020-04-08 10:28:11 +02:00
parent 8af3216c4c
commit f79d60e0c7
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764

View file

@ -26,6 +26,9 @@
%% ct. %% ct.
suite() ->
[{timetrap, 30000}].
all() -> all() ->
cowboy_test:common_all(). cowboy_test:common_all().
@ -112,9 +115,8 @@ do_get(Path, UserData, Config) ->
{<<"accept-encoding">>, <<"gzip">>}, {<<"accept-encoding">>, <<"gzip">>},
{<<"x-test-pid">>, pid_to_list(self())} {<<"x-test-pid">>, pid_to_list(self())}
]), ]),
{response, nofin, 200, RespHeaders} = gun:await(ConnPid, Ref), {response, nofin, 200, RespHeaders} = gun:await(ConnPid, Ref, infinity),
{ok, RespBody} = gun:await_body(ConnPid, Ref), {ok, RespBody} = gun:await_body(ConnPid, Ref, infinity),
gun:close(ConnPid),
%% Receive the metrics and validate them. %% Receive the metrics and validate them.
receive receive
{metrics, From, Metrics} -> {metrics, From, Metrics} ->
@ -162,9 +164,7 @@ do_get(Path, UserData, Config) ->
user_data := UserData user_data := UserData
} = Metrics, } = Metrics,
%% All good! %% All good!
ok gun:close(ConnPid)
after 1000 ->
error(timeout)
end. end.
post_body(Config) -> post_body(Config) ->
@ -176,9 +176,8 @@ post_body(Config) ->
{<<"accept-encoding">>, <<"gzip">>}, {<<"accept-encoding">>, <<"gzip">>},
{<<"x-test-pid">>, pid_to_list(self())} {<<"x-test-pid">>, pid_to_list(self())}
], Body), ], Body),
{response, nofin, 200, RespHeaders} = gun:await(ConnPid, Ref), {response, nofin, 200, RespHeaders} = gun:await(ConnPid, Ref, infinity),
{ok, RespBody} = gun:await_body(ConnPid, Ref), {ok, RespBody} = gun:await_body(ConnPid, Ref, infinity),
gun:close(ConnPid),
%% Receive the metrics and validate them. %% Receive the metrics and validate them.
receive receive
{metrics, From, Metrics} -> {metrics, From, Metrics} ->
@ -226,9 +225,7 @@ post_body(Config) ->
user_data := #{} user_data := #{}
} = Metrics, } = Metrics,
%% All good! %% All good!
ok gun:close(ConnPid)
after 1000 ->
error(timeout)
end. end.
no_resp_body(Config) -> no_resp_body(Config) ->
@ -239,8 +236,7 @@ no_resp_body(Config) ->
{<<"accept-encoding">>, <<"gzip">>}, {<<"accept-encoding">>, <<"gzip">>},
{<<"x-test-pid">>, pid_to_list(self())} {<<"x-test-pid">>, pid_to_list(self())}
]), ]),
{response, fin, 204, RespHeaders} = gun:await(ConnPid, Ref), {response, fin, 204, RespHeaders} = gun:await(ConnPid, Ref, infinity),
gun:close(ConnPid),
%% Receive the metrics and validate them. %% Receive the metrics and validate them.
receive receive
{metrics, From, Metrics} -> {metrics, From, Metrics} ->
@ -284,9 +280,7 @@ no_resp_body(Config) ->
user_data := #{} user_data := #{}
} = Metrics, } = Metrics,
%% All good! %% All good!
ok gun:close(ConnPid)
after 1000 ->
error(timeout)
end. end.
early_error(Config) -> early_error(Config) ->
@ -303,8 +297,7 @@ early_error(Config) ->
{<<"accept-encoding">>, <<"gzip">>}, {<<"accept-encoding">>, <<"gzip">>},
{<<"x-test-pid">>, pid_to_list(self())} {<<"x-test-pid">>, pid_to_list(self())}
|Headers], <<>>), |Headers], <<>>),
{response, fin, Status, RespHeaders} = gun:await(ConnPid, Ref), {response, fin, Status, RespHeaders} = gun:await(ConnPid, Ref, infinity),
gun:close(ConnPid),
%% Receive the metrics and validate them. %% Receive the metrics and validate them.
receive receive
{metrics, From, Metrics} -> {metrics, From, Metrics} ->
@ -322,9 +315,7 @@ early_error(Config) ->
} = Metrics, } = Metrics,
ExpectedRespHeaders = maps:from_list(RespHeaders), ExpectedRespHeaders = maps:from_list(RespHeaders),
%% All good! %% All good!
ok gun:close(ConnPid)
after 1000 ->
error(timeout)
end. end.
early_error_request_line(Config) -> early_error_request_line(Config) ->
@ -361,8 +352,6 @@ do_early_error_request_line(Config) ->
ExpectedRespHeaders = maps:from_list(RespHeaders), ExpectedRespHeaders = maps:from_list(RespHeaders),
%% All good! %% All good!
ok ok
after 1000 ->
error(timeout)
end. end.
%% This test is identical to normal GET except for the handler. %% This test is identical to normal GET except for the handler.
@ -379,7 +368,7 @@ ws(Config) ->
do_ws(Config) -> do_ws(Config) ->
doc("Confirm metrics are correct when switching to Websocket."), doc("Confirm metrics are correct when switching to Websocket."),
ConnPid = gun_open(Config), ConnPid = gun_open(Config),
{ok, http} = gun:await_up(ConnPid), {ok, http} = gun:await_up(ConnPid, infinity),
StreamRef = gun:ws_upgrade(ConnPid, "/ws_echo", [ StreamRef = gun:ws_upgrade(ConnPid, "/ws_echo", [
{<<"accept-encoding">>, <<"gzip">>}, {<<"accept-encoding">>, <<"gzip">>},
{<<"x-test-pid">>, pid_to_list(self())} {<<"x-test-pid">>, pid_to_list(self())}
@ -433,15 +422,11 @@ do_ws(Config) ->
} = Metrics, } = Metrics,
%% All good! %% All good!
ok ok
after 1000 ->
error(timeout)
end, end,
%% And of course the upgrade completed successfully after that. %% And of course the upgrade completed successfully after that.
receive receive
{gun_upgrade, ConnPid, StreamRef, _, _} -> {gun_upgrade, ConnPid, StreamRef, _, _} ->
ok ok
after 1000 ->
error(timeout)
end, end,
gun:close(ConnPid). gun:close(ConnPid).
@ -453,9 +438,8 @@ error_response(Config) ->
{<<"accept-encoding">>, <<"gzip">>}, {<<"accept-encoding">>, <<"gzip">>},
{<<"x-test-pid">>, pid_to_list(self())} {<<"x-test-pid">>, pid_to_list(self())}
]), ]),
{response, fin, 500, RespHeaders} = gun:await(ConnPid, Ref), {response, fin, 500, RespHeaders} = gun:await(ConnPid, Ref, infinity),
timer:sleep(100), timer:sleep(100),
gun:close(ConnPid),
%% Receive the metrics and validate them. %% Receive the metrics and validate them.
receive receive
{metrics, From, Metrics} -> {metrics, From, Metrics} ->
@ -499,9 +483,7 @@ error_response(Config) ->
user_data := #{} user_data := #{}
} = Metrics, } = Metrics,
%% All good! %% All good!
ok gun:close(ConnPid)
after 1000 ->
error(timeout)
end. end.
error_response_after_reply(Config) -> error_response_after_reply(Config) ->
@ -513,9 +495,8 @@ error_response_after_reply(Config) ->
{<<"accept-encoding">>, <<"gzip">>}, {<<"accept-encoding">>, <<"gzip">>},
{<<"x-test-pid">>, pid_to_list(self())} {<<"x-test-pid">>, pid_to_list(self())}
]), ]),
{response, fin, 200, RespHeaders} = gun:await(ConnPid, Ref), {response, fin, 200, RespHeaders} = gun:await(ConnPid, Ref, infinity),
timer:sleep(100), timer:sleep(100),
gun:close(ConnPid),
%% Receive the metrics and validate them. %% Receive the metrics and validate them.
receive receive
{metrics, From, Metrics} -> {metrics, From, Metrics} ->
@ -559,7 +540,5 @@ error_response_after_reply(Config) ->
user_data := #{} user_data := #{}
} = Metrics, } = Metrics,
%% All good! %% All good!
ok gun:close(ConnPid)
after 1000 ->
error(timeout)
end. end.