mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Change send_timeout_close test to accomodate macOS
This commit is contained in:
parent
efb681d749
commit
67bd791dcc
3 changed files with 28 additions and 21 deletions
|
@ -19,6 +19,7 @@ init(Req0, #{delay := Delay} = Opts) ->
|
||||||
{cowboy_loop, Req, Opts}.
|
{cowboy_loop, Req, Opts}.
|
||||||
|
|
||||||
info(timeout, Req, State) ->
|
info(timeout, Req, State) ->
|
||||||
cowboy_req:stream_body(<<0:1000/unit:8>>, nofin, Req),
|
cowboy_req:stream_body(<<0:10000/unit:8>>, nofin, Req),
|
||||||
erlang:send_after(10, self(), timeout),
|
%% Equivalent to a 0 timeout.
|
||||||
|
self() ! timeout,
|
||||||
{ok, Req, State}.
|
{ok, Req, State}.
|
||||||
|
|
|
@ -448,7 +448,13 @@ send_timeout_close(Config) ->
|
||||||
{<<":path">>, <<"/endless">>},
|
{<<":path">>, <<"/endless">>},
|
||||||
{<<"x-test-pid">>, pid_to_list(self())}
|
{<<"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,
|
%% Wait for the handler to start then get its pid,
|
||||||
%% the remote connection's pid and socket.
|
%% the remote connection's pid and socket.
|
||||||
StreamPid = receive
|
StreamPid = receive
|
||||||
|
@ -462,19 +468,19 @@ send_timeout_close(Config) ->
|
||||||
[ServerSocket] = [PidOrPort || PidOrPort <- ServerLinks, is_port(PidOrPort)],
|
[ServerSocket] = [PidOrPort || PidOrPort <- ServerLinks, is_port(PidOrPort)],
|
||||||
%% Poll the socket repeatedly until it is closed by the server.
|
%% Poll the socket repeatedly until it is closed by the server.
|
||||||
WaitClosedFun =
|
WaitClosedFun =
|
||||||
fun F(T, Status) when T =< 0 ->
|
fun F(T) when T =< 0 ->
|
||||||
error({status, Status});
|
error({status, prim_inet:getstatus(ServerSocket)});
|
||||||
F(T, _) ->
|
F(T) ->
|
||||||
case prim_inet:getstatus(ServerSocket) of
|
|
||||||
{error, _} ->
|
|
||||||
ok;
|
|
||||||
{ok, Status} ->
|
|
||||||
Snooze = 100,
|
Snooze = 100,
|
||||||
|
case inet:sockname(ServerSocket) of
|
||||||
|
{error, _} ->
|
||||||
|
timer:sleep(Snooze);
|
||||||
|
{ok, _} ->
|
||||||
timer:sleep(Snooze),
|
timer:sleep(Snooze),
|
||||||
F(T - Snooze, Status)
|
F(T - Snooze)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
ok = WaitClosedFun(2000, undefined),
|
ok = WaitClosedFun(2000),
|
||||||
false = erlang:is_process_alive(StreamPid),
|
false = erlang:is_process_alive(StreamPid),
|
||||||
false = erlang:is_process_alive(ServerPid)
|
false = erlang:is_process_alive(ServerPid)
|
||||||
after
|
after
|
||||||
|
|
|
@ -556,19 +556,19 @@ send_timeout_close(_Config) ->
|
||||||
[ServerSocket] = [PidOrPort || PidOrPort <- ServerLinks, is_port(PidOrPort)],
|
[ServerSocket] = [PidOrPort || PidOrPort <- ServerLinks, is_port(PidOrPort)],
|
||||||
%% Poll the socket repeatedly until it is closed by the server.
|
%% Poll the socket repeatedly until it is closed by the server.
|
||||||
WaitClosedFun =
|
WaitClosedFun =
|
||||||
fun F(T, Status) when T =< 0 ->
|
fun F(T) when T =< 0 ->
|
||||||
error({status, Status});
|
error({status, prim_inet:getstatus(ServerSocket)});
|
||||||
F(T, _) ->
|
F(T) ->
|
||||||
case prim_inet:getstatus(ServerSocket) of
|
|
||||||
{error, _} ->
|
|
||||||
ok;
|
|
||||||
{ok, Status} ->
|
|
||||||
Snooze = 100,
|
Snooze = 100,
|
||||||
|
case inet:sockname(ServerSocket) of
|
||||||
|
{error, _} ->
|
||||||
|
timer:sleep(Snooze);
|
||||||
|
{ok, _} ->
|
||||||
timer:sleep(Snooze),
|
timer:sleep(Snooze),
|
||||||
F(T - Snooze, Status)
|
F(T - Snooze)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
ok = WaitClosedFun(2000, undefined),
|
ok = WaitClosedFun(2000),
|
||||||
false = erlang:is_process_alive(StreamPid),
|
false = erlang:is_process_alive(StreamPid),
|
||||||
false = erlang:is_process_alive(ServerPid)
|
false = erlang:is_process_alive(ServerPid)
|
||||||
after
|
after
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue