aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2023-12-13 17:24:48 +0100
committerLoïc Hoguin <[email protected]>2023-12-14 15:25:25 +0100
commit67bd791dcc6138758a9f4d0a071f2369301c7373 (patch)
tree6f52d5ab186172f0b91d1e8c27f300071e6c4e93
parentefb681d74982dd048638b00c3c275091ba1d4a2a (diff)
downloadcowboy-67bd791dcc6138758a9f4d0a071f2369301c7373.tar.gz
cowboy-67bd791dcc6138758a9f4d0a071f2369301c7373.tar.bz2
cowboy-67bd791dcc6138758a9f4d0a071f2369301c7373.zip
Change send_timeout_close test to accomodate macOS
-rw-r--r--test/handlers/loop_handler_endless_h.erl5
-rw-r--r--test/http2_SUITE.erl26
-rw-r--r--test/http_SUITE.erl18
3 files changed, 28 insertions, 21 deletions
diff --git a/test/handlers/loop_handler_endless_h.erl b/test/handlers/loop_handler_endless_h.erl
index f18361f..d8c8ab5 100644
--- a/test/handlers/loop_handler_endless_h.erl
+++ b/test/handlers/loop_handler_endless_h.erl
@@ -19,6 +19,7 @@ init(Req0, #{delay := Delay} = Opts) ->
{cowboy_loop, Req, Opts}.
info(timeout, Req, State) ->
- cowboy_req:stream_body(<<0:1000/unit:8>>, nofin, Req),
- erlang:send_after(10, self(), timeout),
+ cowboy_req:stream_body(<<0:10000/unit:8>>, nofin, Req),
+ %% Equivalent to a 0 timeout.
+ self() ! timeout,
{ok, Req, State}.
diff --git a/test/http2_SUITE.erl b/test/http2_SUITE.erl
index 0444060..3f81ed7 100644
--- a/test/http2_SUITE.erl
+++ b/test/http2_SUITE.erl
@@ -448,7 +448,13 @@ send_timeout_close(Config) ->
{<<":path">>, <<"/endless">>},
{<<"x-test-pid">>, pid_to_list(self())}
]),
- ok = gen_tcp:send(ClientSocket, cow_http2:headers(1, fin, HeadersBlock)),
+ ok = gen_tcp:send(ClientSocket, [
+ cow_http2:headers(1, fin, HeadersBlock),
+ %% Greatly increase the window to make sure we don't run
+ %% out of space before we get send timeouts.
+ cow_http2:window_update(10000000),
+ cow_http2:window_update(1, 10000000)
+ ]),
%% Wait for the handler to start then get its pid,
%% the remote connection's pid and socket.
StreamPid = receive
@@ -462,19 +468,19 @@ send_timeout_close(Config) ->
[ServerSocket] = [PidOrPort || PidOrPort <- ServerLinks, is_port(PidOrPort)],
%% Poll the socket repeatedly until it is closed by the server.
WaitClosedFun =
- fun F(T, Status) when T =< 0 ->
- error({status, Status});
- F(T, _) ->
- case prim_inet:getstatus(ServerSocket) of
+ fun F(T) when T =< 0 ->
+ error({status, prim_inet:getstatus(ServerSocket)});
+ F(T) ->
+ Snooze = 100,
+ case inet:sockname(ServerSocket) of
{error, _} ->
- ok;
- {ok, Status} ->
- Snooze = 100,
+ timer:sleep(Snooze);
+ {ok, _} ->
timer:sleep(Snooze),
- F(T - Snooze, Status)
+ F(T - Snooze)
end
end,
- ok = WaitClosedFun(2000, undefined),
+ ok = WaitClosedFun(2000),
false = erlang:is_process_alive(StreamPid),
false = erlang:is_process_alive(ServerPid)
after
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl
index 28118a6..e3ac553 100644
--- a/test/http_SUITE.erl
+++ b/test/http_SUITE.erl
@@ -556,19 +556,19 @@ send_timeout_close(_Config) ->
[ServerSocket] = [PidOrPort || PidOrPort <- ServerLinks, is_port(PidOrPort)],
%% Poll the socket repeatedly until it is closed by the server.
WaitClosedFun =
- fun F(T, Status) when T =< 0 ->
- error({status, Status});
- F(T, _) ->
- case prim_inet:getstatus(ServerSocket) of
+ fun F(T) when T =< 0 ->
+ error({status, prim_inet:getstatus(ServerSocket)});
+ F(T) ->
+ Snooze = 100,
+ case inet:sockname(ServerSocket) of
{error, _} ->
- ok;
- {ok, Status} ->
- Snooze = 100,
+ timer:sleep(Snooze);
+ {ok, _} ->
timer:sleep(Snooze),
- F(T - Snooze, Status)
+ F(T - Snooze)
end
end,
- ok = WaitClosedFun(2000, undefined),
+ ok = WaitClosedFun(2000),
false = erlang:is_process_alive(StreamPid),
false = erlang:is_process_alive(ServerPid)
after