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

Fix intermittent failures in sys_SUITE

This commit is contained in:
Loïc Hoguin 2019-09-15 10:01:32 +02:00
parent 49af57d546
commit e28a339ccd
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764

View file

@ -409,12 +409,7 @@ trap_exit_other_exit_h2(Config) ->
"'EXIT' messages from unknown processes."), "'EXIT' messages from unknown processes."),
{ok, Socket} = ssl:connect("localhost", config(tls_port, Config), {ok, Socket} = ssl:connect("localhost", config(tls_port, Config),
[{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]), [{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]),
%% Do the handshake. do_http2_handshake(Socket),
ok = ssl:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
{ok, <<_,_,_,4,_/bits>>} = ssl:recv(Socket, 0, 1000),
ok = ssl:send(Socket, cow_http2:settings_ack()),
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = ssl:recv(Socket, 9, 1000),
timer:sleep(100),
Pid = get_remote_pid_tls(Socket), Pid = get_remote_pid_tls(Socket),
Pid ! {'EXIT', self(), {shutdown, ?MODULE}}, Pid ! {'EXIT', self(), {shutdown, ?MODULE}},
%% Send a HEADERS frame as a request. %% Send a HEADERS frame as a request.
@ -532,17 +527,8 @@ sys_change_code_h2(Config) ->
doc("h2: The sys:change_code/4 function works as expected."), doc("h2: The sys:change_code/4 function works as expected."),
{ok, Socket} = ssl:connect("localhost", config(tls_port, Config), {ok, Socket} = ssl:connect("localhost", config(tls_port, Config),
[{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]), [{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]),
timer:sleep(100), do_http2_handshake(Socket),
Pid = get_remote_pid_tls(Socket), Pid = get_remote_pid_tls(Socket),
%% Send a valid preface.
ok = ssl:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
%% Receive the server preface.
{ok, << Len:24 >>} = ssl:recv(Socket, 3, 1000),
{ok, << 4:8, 0:40, _:Len/binary >>} = ssl:recv(Socket, 6 + Len, 1000),
%% Send the SETTINGS ack.
ok = ssl:send(Socket, cow_http2:settings_ack()),
%% Receive the SETTINGS ack.
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = ssl:recv(Socket, 9, 1000),
%% Suspend the process and try to get a request in. The %% Suspend the process and try to get a request in. The
%% response will not come back until we resume the process. %% response will not come back until we resume the process.
ok = sys:suspend(Pid), ok = sys:suspend(Pid),
@ -818,17 +804,8 @@ sys_suspend_and_resume_h2(Config) ->
doc("h2: The sys:suspend/1 and sys:resume/1 functions work as expected."), doc("h2: The sys:suspend/1 and sys:resume/1 functions work as expected."),
{ok, Socket} = ssl:connect("localhost", config(tls_port, Config), {ok, Socket} = ssl:connect("localhost", config(tls_port, Config),
[{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]), [{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]),
timer:sleep(100), do_http2_handshake(Socket),
Pid = get_remote_pid_tls(Socket), Pid = get_remote_pid_tls(Socket),
%% Send a valid preface.
ok = ssl:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
%% Receive the server preface.
{ok, << Len:24 >>} = ssl:recv(Socket, 3, 1000),
{ok, << 4:8, 0:40, _:Len/binary >>} = ssl:recv(Socket, 6 + Len, 1000),
%% Send the SETTINGS ack.
ok = ssl:send(Socket, cow_http2:settings_ack()),
%% Receive the SETTINGS ack.
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = ssl:recv(Socket, 9, 1000),
%% Suspend the process and try to get a request in. The %% Suspend the process and try to get a request in. The
%% response will not come back until we resume the process. %% response will not come back until we resume the process.
ok = sys:suspend(Pid), ok = sys:suspend(Pid),
@ -1009,12 +986,7 @@ supervisor_count_children_h2(Config) ->
doc("h2: The function supervisor:count_children/1 must work."), doc("h2: The function supervisor:count_children/1 must work."),
{ok, Socket} = ssl:connect("localhost", config(tls_port, Config), {ok, Socket} = ssl:connect("localhost", config(tls_port, Config),
[{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]), [{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]),
%% Do the handshake. do_http2_handshake(Socket),
ok = ssl:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
{ok, <<_,_,_,4,_/bits>>} = ssl:recv(Socket, 0, 1000),
ok = ssl:send(Socket, cow_http2:settings_ack()),
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = ssl:recv(Socket, 9, 1000),
timer:sleep(100),
Pid = get_remote_pid_tls(Socket), Pid = get_remote_pid_tls(Socket),
%% No request was sent so there's no children. %% No request was sent so there's no children.
Counts1 = supervisor:count_children(Pid), Counts1 = supervisor:count_children(Pid),
@ -1086,12 +1058,7 @@ supervisor_delete_child_not_found_h2(Config) ->
doc("h2: The function supervisor:delete_child/2 must return {error, not_found}."), doc("h2: The function supervisor:delete_child/2 must return {error, not_found}."),
{ok, Socket} = ssl:connect("localhost", config(tls_port, Config), {ok, Socket} = ssl:connect("localhost", config(tls_port, Config),
[{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]), [{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]),
%% Do the handshake. do_http2_handshake(Socket),
ok = ssl:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
{ok, <<_,_,_,4,_/bits>>} = ssl:recv(Socket, 0, 1000),
ok = ssl:send(Socket, cow_http2:settings_ack()),
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = ssl:recv(Socket, 9, 1000),
timer:sleep(100),
Pid = get_remote_pid_tls(Socket), Pid = get_remote_pid_tls(Socket),
%% When no children exist. %% When no children exist.
{error, not_found} = supervisor:delete_child(Pid, cowboy_http2), {error, not_found} = supervisor:delete_child(Pid, cowboy_http2),
@ -1150,12 +1117,7 @@ supervisor_get_childspec_not_found_h2(Config) ->
doc("h2: The function supervisor:get_childspec/2 must return {error, not_found}."), doc("h2: The function supervisor:get_childspec/2 must return {error, not_found}."),
{ok, Socket} = ssl:connect("localhost", config(tls_port, Config), {ok, Socket} = ssl:connect("localhost", config(tls_port, Config),
[{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]), [{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]),
%% Do the handshake. do_http2_handshake(Socket),
ok = ssl:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
{ok, <<_,_,_,4,_/bits>>} = ssl:recv(Socket, 0, 1000),
ok = ssl:send(Socket, cow_http2:settings_ack()),
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = ssl:recv(Socket, 9, 1000),
timer:sleep(100),
Pid = get_remote_pid_tls(Socket), Pid = get_remote_pid_tls(Socket),
%% When no children exist. %% When no children exist.
{error, not_found} = supervisor:get_childspec(Pid, cowboy_http2), {error, not_found} = supervisor:get_childspec(Pid, cowboy_http2),
@ -1214,12 +1176,7 @@ supervisor_restart_child_not_found_h2(Config) ->
doc("h2: The function supervisor:restart_child/2 must return {error, not_found}."), doc("h2: The function supervisor:restart_child/2 must return {error, not_found}."),
{ok, Socket} = ssl:connect("localhost", config(tls_port, Config), {ok, Socket} = ssl:connect("localhost", config(tls_port, Config),
[{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]), [{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]),
%% Do the handshake. do_http2_handshake(Socket),
ok = ssl:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
{ok, <<_,_,_,4,_/bits>>} = ssl:recv(Socket, 0, 1000),
ok = ssl:send(Socket, cow_http2:settings_ack()),
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = ssl:recv(Socket, 9, 1000),
timer:sleep(100),
Pid = get_remote_pid_tls(Socket), Pid = get_remote_pid_tls(Socket),
%% When no children exist. %% When no children exist.
{error, not_found} = supervisor:restart_child(Pid, cowboy_http2), {error, not_found} = supervisor:restart_child(Pid, cowboy_http2),
@ -1273,12 +1230,7 @@ supervisor_start_child_not_found_h2(Config) ->
doc("h2: The function supervisor:start_child/2 must return {error, start_child_disabled}."), doc("h2: The function supervisor:start_child/2 must return {error, start_child_disabled}."),
{ok, Socket} = ssl:connect("localhost", config(tls_port, Config), {ok, Socket} = ssl:connect("localhost", config(tls_port, Config),
[{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]), [{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]),
%% Do the handshake. do_http2_handshake(Socket),
ok = ssl:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
{ok, <<_,_,_,4,_/bits>>} = ssl:recv(Socket, 0, 1000),
ok = ssl:send(Socket, cow_http2:settings_ack()),
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = ssl:recv(Socket, 9, 1000),
timer:sleep(100),
Pid = get_remote_pid_tls(Socket), Pid = get_remote_pid_tls(Socket),
{error, start_child_disabled} = supervisor:start_child(Pid, #{ {error, start_child_disabled} = supervisor:start_child(Pid, #{
id => error, id => error,
@ -1332,12 +1284,7 @@ supervisor_terminate_child_not_found_h2(Config) ->
doc("h2: The function supervisor:terminate_child/2 must return {error, not_found}."), doc("h2: The function supervisor:terminate_child/2 must return {error, not_found}."),
{ok, Socket} = ssl:connect("localhost", config(tls_port, Config), {ok, Socket} = ssl:connect("localhost", config(tls_port, Config),
[{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]), [{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]),
%% Do the handshake. do_http2_handshake(Socket),
ok = ssl:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
{ok, <<_,_,_,4,_/bits>>} = ssl:recv(Socket, 0, 1000),
ok = ssl:send(Socket, cow_http2:settings_ack()),
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = ssl:recv(Socket, 9, 1000),
timer:sleep(100),
Pid = get_remote_pid_tls(Socket), Pid = get_remote_pid_tls(Socket),
%% When no children exist. %% When no children exist.
{error, not_found} = supervisor:terminate_child(Pid, cowboy_http2), {error, not_found} = supervisor:terminate_child(Pid, cowboy_http2),
@ -1400,12 +1347,7 @@ supervisor_which_children_h2(Config) ->
doc("h2: The function supervisor:which_children/1 must work."), doc("h2: The function supervisor:which_children/1 must work."),
{ok, Socket} = ssl:connect("localhost", config(tls_port, Config), {ok, Socket} = ssl:connect("localhost", config(tls_port, Config),
[{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]), [{active, false}, binary, {alpn_advertised_protocols, [<<"h2">>]}]),
%% Do the handshake. do_http2_handshake(Socket),
ok = ssl:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
{ok, <<_,_,_,4,_/bits>>} = ssl:recv(Socket, 0, 1000),
ok = ssl:send(Socket, cow_http2:settings_ack()),
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = ssl:recv(Socket, 9, 1000),
timer:sleep(100),
Pid = get_remote_pid_tls(Socket), Pid = get_remote_pid_tls(Socket),
%% No request was sent so there's no children. %% No request was sent so there's no children.
[] = supervisor:which_children(Pid), [] = supervisor:which_children(Pid),
@ -1442,3 +1384,12 @@ supervisor_which_children_ws(Config) ->
Pid = get_remote_pid_tcp(Socket), Pid = get_remote_pid_tcp(Socket),
[] = supervisor:which_children(Pid), [] = supervisor:which_children(Pid),
ok. ok.
%% Internal.
do_http2_handshake(Socket) ->
ok = ssl:send(Socket, "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"),
{ok, <<_,_,_,4,_/bits>>} = ssl:recv(Socket, 0, 1000),
ok = ssl:send(Socket, [cow_http2:settings(#{}), cow_http2:settings_ack()]),
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = ssl:recv(Socket, 9, 1000),
ok.