Skip to content

Commit

Permalink
Correctly detect cowboy_tls process
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed May 14, 2021
1 parent 55efbb1 commit 3ea2ba9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 6 additions & 6 deletions test/cowboy_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@
%% Listeners initialization.

init_http(Ref, ProtoOpts, Config) ->
{ok, _} = cowboy:start_clear(Ref, [{port, 0}], ProtoOpts),
{ok, Pid} = cowboy:start_clear(Ref, [{port, 0}], ProtoOpts),
Port = ranch:get_port(Ref),
[{ref, Ref}, {type, tcp}, {protocol, http}, {port, Port}, {opts, []}|Config].
[{supervisor, Pid}, {ref, Ref}, {type, tcp}, {protocol, http}, {port, Port}, {opts, []}|Config].

init_https(Ref, ProtoOpts, Config) ->
Opts = ct_helper:get_certs_from_ets(),
{ok, _} = cowboy:start_tls(Ref, Opts ++ [{port, 0}], ProtoOpts),
{ok, Pid} = cowboy:start_tls(Ref, Opts ++ [{port, 0}], ProtoOpts),
Port = ranch:get_port(Ref),
[{ref, Ref}, {type, ssl}, {protocol, http}, {port, Port}, {opts, Opts}|Config].
[{supervisor, Pid}, {ref, Ref}, {type, ssl}, {protocol, http}, {port, Port}, {opts, Opts}|Config].

init_http2(Ref, ProtoOpts, Config) ->
Opts = ct_helper:get_certs_from_ets(),
{ok, _} = cowboy:start_tls(Ref, Opts ++ [{port, 0}], ProtoOpts),
{ok, Pid} = cowboy:start_tls(Ref, Opts ++ [{port, 0}], ProtoOpts),
Port = ranch:get_port(Ref),
[{ref, Ref}, {type, ssl}, {protocol, http2}, {port, Port}, {opts, Opts}|Config].
[{supervisor, Pid}, {ref, Ref}, {type, ssl}, {protocol, http2}, {port, Port}, {opts, Opts}|Config].

%% Common group of listeners used by most suites.

Expand Down
12 changes: 10 additions & 2 deletions test/proxy_header_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ fail_gracefully_on_disconnect(Config) ->
doc("Probing a port does not generate a crash"),
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config),
[binary, {active, false}, {packet, raw}]),
timer:sleep(100),
Pid = ct_helper:get_remote_pid_tcp(Socket),
timer:sleep(50),
Pid = do_get_sockets_pid(Config, Socket, config(type, Config)),
Ref = erlang:monitor(process, Pid),
gen_tcp:close(Socket),
receive
Expand Down Expand Up @@ -252,3 +252,11 @@ do_recv_101(Client) ->
"\r\n"
>>} = raw_recv(Client, 71, 1000),
ok.

do_get_sockets_pid(_Config, Socket, tcp) ->
ct_helper:get_remote_pid_tcp(Socket);
do_get_sockets_pid(Config, _Socket, ssl) ->
Sup = config(supervisor, Config),
{_, RanchConns, _, _} = lists:keyfind(ranch_conns_sup, 1, supervisor:which_children(Sup)),
{_, CowboyTls, _, _} = lists:keyfind(cowboy_tls, 1, supervisor:which_children(RanchConns)),
CowboyTls.

0 comments on commit 3ea2ba9

Please sign in to comment.