aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-04-25 12:01:58 +0200
committerLoïc Hoguin <[email protected]>2019-04-25 12:01:58 +0200
commit97857d23dda07524631c15ad1eb876d109eb6829 (patch)
treef3becebb875ee93cf63b5d13987f07351c01e72c /test
parent57abad2d59323e64144246a9af6ce0fc91711a6f (diff)
downloadgun-97857d23dda07524631c15ad1eb876d109eb6829.tar.gz
gun-97857d23dda07524631c15ad1eb876d109eb6829.tar.bz2
gun-97857d23dda07524631c15ad1eb876d109eb6829.zip
Fix failures resulting from connect error delays on Windows
On Windows when the connection is refused the OS will retry 3 times before giving up, with a 500ms delay between tries. This adds approximately 1 second to connection failures.
Diffstat (limited to 'test')
-rw-r--r--test/gun_SUITE.erl55
1 files changed, 39 insertions, 16 deletions
diff --git a/test/gun_SUITE.erl b/test/gun_SUITE.erl
index c38395a..9f5aa3a 100644
--- a/test/gun_SUITE.erl
+++ b/test/gun_SUITE.erl
@@ -315,10 +315,17 @@ retry_0(_) ->
doc("Ensure Gun gives up immediately with retry=0."),
{ok, Pid} = gun:open("localhost", 12345, #{retry => 0, retry_timeout => 500}),
Ref = monitor(process, Pid),
+ %% On Windows when the connection is refused the OS will retry
+ %% 3 times before giving up, with a 500ms delay between tries.
+ %% This adds approximately 1 second to connection failures.
+ After = case os:type() of
+ {win32, _} -> 1200;
+ _ -> 200
+ end,
receive
{'DOWN', Ref, process, Pid, {shutdown, _}} ->
ok
- after 200 ->
+ after After ->
error(timeout)
end.
@@ -326,10 +333,14 @@ retry_1(_) ->
doc("Ensure Gun gives up with retry=1."),
{ok, Pid} = gun:open("localhost", 12345, #{retry => 1, retry_timeout => 500}),
Ref = monitor(process, Pid),
+ After = case os:type() of
+ {win32, _} -> 2700;
+ _ -> 700
+ end,
receive
{'DOWN', Ref, process, Pid, {shutdown, _}} ->
ok
- after 700 ->
+ after After ->
error(timeout)
end.
@@ -342,10 +353,14 @@ retry_immediately(_) ->
end),
{ok, Pid} = gun:open("localhost", OriginPort, #{retry => 1, retry_timeout => 500}),
Ref = monitor(process, Pid),
+ After = case os:type() of
+ {win32, _} -> 1200;
+ _ -> 200
+ end,
receive
{'DOWN', Ref, process, Pid, {shutdown, _}} ->
ok
- after 200 ->
+ after After ->
error(timeout)
end.
@@ -353,19 +368,38 @@ retry_timeout(_) ->
doc("Ensure the retry_timeout value is enforced."),
{ok, Pid} = gun:open("localhost", 12345, #{retry => 1, retry_timeout => 1000}),
Ref = monitor(process, Pid),
+ After = case os:type() of
+ {win32, _} -> 2800;
+ _ -> 800
+ end,
receive
{'DOWN', Ref, process, Pid, {shutdown, _}} ->
error(shutdown_too_early)
- after 800 ->
+ after After ->
ok
end,
receive
{'DOWN', Ref, process, Pid, {shutdown, _}} ->
ok
- after 800 ->
+ after After ->
error(shutdown_too_late)
end.
+shutdown_reason(_) ->
+ doc("The last connection failure must be propagated."),
+ {ok, Pid} = gun:open("localhost", 12345, #{retry => 0}),
+ Ref = monitor(process, Pid),
+ After = case os:type() of
+ {win32, _} -> 1200;
+ _ -> 200
+ end,
+ receive
+ {'DOWN', Ref, process, Pid, {shutdown, econnrefused}} ->
+ ok
+ after After ->
+ error(timeout)
+ 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,
@@ -427,17 +461,6 @@ stream_info_http2(_) ->
{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}),
- Ref = monitor(process, Pid),
- receive
- {'DOWN', Ref, process, Pid, {shutdown, econnrefused}} ->
- ok
- after 200 ->
- error(timeout)
- end.
-
transform_header_name(_) ->
doc("The transform_header_name option allows changing the case of header names."),
{ok, ListenSocket} = gen_tcp:listen(0, [binary, {active, false}]),