mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Move listener initialization to cowboy_test
This commit is contained in:
parent
b377eb9805
commit
25a17a2590
4 changed files with 65 additions and 59 deletions
|
@ -49,6 +49,34 @@ all(Suite) ->
|
||||||
string:substr(atom_to_list(F), 1, 3) =/= "do_"
|
string:substr(atom_to_list(F), 1, 3) =/= "do_"
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
%% Listeners initialization.
|
||||||
|
|
||||||
|
init_http(Ref, ProtoOpts, Config) ->
|
||||||
|
{ok, _} = cowboy:start_http(Ref, 100, [{port, 0}], [
|
||||||
|
{max_keepalive, 50},
|
||||||
|
{timeout, 500}
|
||||||
|
|ProtoOpts]),
|
||||||
|
Port = ranch:get_port(Ref),
|
||||||
|
[{type, tcp}, {port, Port}, {opts, []}|Config].
|
||||||
|
|
||||||
|
init_https(Ref, ProtoOpts, Config) ->
|
||||||
|
{_, Cert, Key} = ct_helper:make_certs(),
|
||||||
|
Opts = [{cert, Cert}, {key, Key}],
|
||||||
|
{ok, _} = cowboy:start_https(Ref, 100, Opts ++ [{port, 0}], [
|
||||||
|
{max_keepalive, 50},
|
||||||
|
{timeout, 500}
|
||||||
|
|ProtoOpts]),
|
||||||
|
Port = ranch:get_port(Ref),
|
||||||
|
[{type, ssl}, {port, Port}, {opts, Opts}|Config].
|
||||||
|
|
||||||
|
init_spdy(Ref, ProtoOpts, Config) ->
|
||||||
|
{_, Cert, Key} = ct_helper:make_certs(),
|
||||||
|
Opts = [{cert, Cert}, {key, Key}],
|
||||||
|
{ok, _} = cowboy:start_spdy(Ref, 100, Opts ++ [{port, 0}],
|
||||||
|
ProtoOpts),
|
||||||
|
Port = ranch:get_port(Ref),
|
||||||
|
[{type, ssl}, {port, Port}, {opts, Opts}|Config].
|
||||||
|
|
||||||
%% Support functions for testing using Gun.
|
%% Support functions for testing using Gun.
|
||||||
|
|
||||||
gun_open(Config) ->
|
gun_open(Config) ->
|
||||||
|
|
|
@ -79,39 +79,26 @@ init_per_suite(Config) ->
|
||||||
end_per_suite(Config) ->
|
end_per_suite(Config) ->
|
||||||
ct_helper:delete_static_dir(config(static_dir, Config)).
|
ct_helper:delete_static_dir(config(static_dir, Config)).
|
||||||
|
|
||||||
init_tcp_group(Ref, ProtoOpts, Config) ->
|
init_per_group(Name = http, Config) ->
|
||||||
Transport = ranch_tcp,
|
cowboy_test:init_http(Name, [
|
||||||
{ok, _} = cowboy:start_http(Ref, 100, [{port, 0}], [
|
{env, [{dispatch, init_dispatch(Config)}]}
|
||||||
|
], Config);
|
||||||
|
init_per_group(Name = https, Config) ->
|
||||||
|
cowboy_test:init_https(Name, [
|
||||||
|
{env, [{dispatch, init_dispatch(Config)}]}
|
||||||
|
], Config);
|
||||||
|
init_per_group(Name = http_compress, Config) ->
|
||||||
|
cowboy_test:init_http(Name, [
|
||||||
{env, [{dispatch, init_dispatch(Config)}]},
|
{env, [{dispatch, init_dispatch(Config)}]},
|
||||||
{max_keepalive, 50},
|
{compress, true}
|
||||||
{timeout, 500}
|
], Config);
|
||||||
|ProtoOpts]),
|
init_per_group(Name = https_compress, Config) ->
|
||||||
Port = ranch:get_port(Ref),
|
cowboy_test:init_https(Name, [
|
||||||
[{type, tcp}, {port, Port}, {opts, []}, {transport, Transport}|Config].
|
|
||||||
|
|
||||||
init_ssl_group(Ref, ProtoOpts, Config) ->
|
|
||||||
Transport = ranch_ssl,
|
|
||||||
{_, Cert, Key} = ct_helper:make_certs(),
|
|
||||||
Opts = [{cert, Cert}, {key, Key}],
|
|
||||||
{ok, _} = cowboy:start_https(Ref, 100, Opts ++ [{port, 0}], [
|
|
||||||
{env, [{dispatch, init_dispatch(Config)}]},
|
{env, [{dispatch, init_dispatch(Config)}]},
|
||||||
{max_keepalive, 50},
|
{compress, true}
|
||||||
{timeout, 500}
|
], Config);
|
||||||
|ProtoOpts]),
|
|
||||||
Port = ranch:get_port(Ref),
|
|
||||||
[{type, ssl}, {port, Port}, {opts, Opts}, {transport, Transport}|Config].
|
|
||||||
|
|
||||||
init_per_group(http, Config) ->
|
|
||||||
init_tcp_group(http, [], Config);
|
|
||||||
init_per_group(https, Config) ->
|
|
||||||
init_ssl_group(https, [], Config);
|
|
||||||
init_per_group(http_compress, Config) ->
|
|
||||||
init_tcp_group(http_compress, [{compress, true}], Config);
|
|
||||||
init_per_group(https_compress, Config) ->
|
|
||||||
init_ssl_group(https_compress, [{compress, true}], Config);
|
|
||||||
%% Most, if not all of these, should be in separate test suites.
|
%% Most, if not all of these, should be in separate test suites.
|
||||||
init_per_group(onrequest, Config) ->
|
init_per_group(onrequest, Config) ->
|
||||||
Transport = ranch_tcp,
|
|
||||||
{ok, _} = cowboy:start_http(onrequest, 100, [{port, 0}], [
|
{ok, _} = cowboy:start_http(onrequest, 100, [{port, 0}], [
|
||||||
{env, [{dispatch, init_dispatch(Config)}]},
|
{env, [{dispatch, init_dispatch(Config)}]},
|
||||||
{max_keepalive, 50},
|
{max_keepalive, 50},
|
||||||
|
@ -119,9 +106,8 @@ init_per_group(onrequest, Config) ->
|
||||||
{timeout, 500}
|
{timeout, 500}
|
||||||
]),
|
]),
|
||||||
Port = ranch:get_port(onrequest),
|
Port = ranch:get_port(onrequest),
|
||||||
[{type, tcp}, {port, Port}, {opts, []}, {transport, Transport}|Config];
|
[{type, tcp}, {port, Port}, {opts, []}|Config];
|
||||||
init_per_group(onresponse, Config) ->
|
init_per_group(onresponse, Config) ->
|
||||||
Transport = ranch_tcp,
|
|
||||||
{ok, _} = cowboy:start_http(onresponse, 100, [{port, 0}], [
|
{ok, _} = cowboy:start_http(onresponse, 100, [{port, 0}], [
|
||||||
{env, [{dispatch, init_dispatch(Config)}]},
|
{env, [{dispatch, init_dispatch(Config)}]},
|
||||||
{max_keepalive, 50},
|
{max_keepalive, 50},
|
||||||
|
@ -129,9 +115,8 @@ init_per_group(onresponse, Config) ->
|
||||||
{timeout, 500}
|
{timeout, 500}
|
||||||
]),
|
]),
|
||||||
Port = ranch:get_port(onresponse),
|
Port = ranch:get_port(onresponse),
|
||||||
[{type, tcp}, {port, Port}, {opts, []}, {transport, Transport}|Config];
|
[{type, tcp}, {port, Port}, {opts, []}|Config];
|
||||||
init_per_group(onresponse_capitalize, Config) ->
|
init_per_group(onresponse_capitalize, Config) ->
|
||||||
Transport = ranch_tcp,
|
|
||||||
{ok, _} = cowboy:start_http(onresponse_capitalize, 100, [{port, 0}], [
|
{ok, _} = cowboy:start_http(onresponse_capitalize, 100, [{port, 0}], [
|
||||||
{env, [{dispatch, init_dispatch(Config)}]},
|
{env, [{dispatch, init_dispatch(Config)}]},
|
||||||
{max_keepalive, 50},
|
{max_keepalive, 50},
|
||||||
|
@ -139,9 +124,8 @@ init_per_group(onresponse_capitalize, Config) ->
|
||||||
{timeout, 500}
|
{timeout, 500}
|
||||||
]),
|
]),
|
||||||
Port = ranch:get_port(onresponse_capitalize),
|
Port = ranch:get_port(onresponse_capitalize),
|
||||||
[{type, tcp}, {port, Port}, {opts, []}, {transport, Transport}|Config];
|
[{type, tcp}, {port, Port}, {opts, []}|Config];
|
||||||
init_per_group(parse_host, Config) ->
|
init_per_group(parse_host, Config) ->
|
||||||
Transport = ranch_tcp,
|
|
||||||
Dispatch = cowboy_router:compile([
|
Dispatch = cowboy_router:compile([
|
||||||
{'_', [
|
{'_', [
|
||||||
{"/req_attr", http_req_attr, []}
|
{"/req_attr", http_req_attr, []}
|
||||||
|
@ -153,20 +137,18 @@ init_per_group(parse_host, Config) ->
|
||||||
{timeout, 500}
|
{timeout, 500}
|
||||||
]),
|
]),
|
||||||
Port = ranch:get_port(http),
|
Port = ranch:get_port(http),
|
||||||
[{type, tcp}, {port, Port}, {opts, []}, {transport, Transport}|Config];
|
[{type, tcp}, {port, Port}, {opts, []}|Config];
|
||||||
init_per_group(set_env, Config) ->
|
init_per_group(set_env, Config) ->
|
||||||
Transport = ranch_tcp,
|
|
||||||
{ok, _} = cowboy:start_http(set_env, 100, [{port, 0}], [
|
{ok, _} = cowboy:start_http(set_env, 100, [{port, 0}], [
|
||||||
{env, [{dispatch, []}]},
|
{env, [{dispatch, []}]},
|
||||||
{max_keepalive, 50},
|
{max_keepalive, 50},
|
||||||
{timeout, 500}
|
{timeout, 500}
|
||||||
]),
|
]),
|
||||||
Port = ranch:get_port(set_env),
|
Port = ranch:get_port(set_env),
|
||||||
[{type, tcp}, {port, Port}, {opts, []}, {transport, Transport}|Config].
|
[{type, tcp}, {port, Port}, {opts, []}|Config].
|
||||||
|
|
||||||
end_per_group(Name, _) ->
|
end_per_group(Name, _) ->
|
||||||
cowboy:stop_listener(Name),
|
cowboy:stop_listener(Name).
|
||||||
ok.
|
|
||||||
|
|
||||||
%% Dispatch configuration.
|
%% Dispatch configuration.
|
||||||
|
|
||||||
|
@ -436,8 +418,12 @@ http10_chunkless(Config) ->
|
||||||
http10_hostless(Config) ->
|
http10_hostless(Config) ->
|
||||||
Port10 = config(port, Config) + 10,
|
Port10 = config(port, Config) + 10,
|
||||||
Name = list_to_atom("http10_hostless_" ++ integer_to_list(Port10)),
|
Name = list_to_atom("http10_hostless_" ++ integer_to_list(Port10)),
|
||||||
ranch:start_listener(Name, 5,
|
Transport = case config(type, Config) of
|
||||||
config(transport, Config), config(opts, Config) ++ [{port, Port10}],
|
tcp -> ranch_tcp;
|
||||||
|
ssl -> ranch_ssl
|
||||||
|
end,
|
||||||
|
ranch:start_listener(Name, 5, Transport,
|
||||||
|
config(opts, Config) ++ [{port, Port10}],
|
||||||
cowboy_protocol, [
|
cowboy_protocol, [
|
||||||
{env, [{dispatch, cowboy_router:compile([
|
{env, [{dispatch, cowboy_router:compile([
|
||||||
{'_', [{"/http1.0/hostless", http_handler, []}]}])}]},
|
{'_', [{"/http1.0/hostless", http_handler, []}]}])}]},
|
||||||
|
|
|
@ -40,17 +40,12 @@ end_per_suite(Config) ->
|
||||||
ct_helper:delete_static_dir(config(static_dir, Config)).
|
ct_helper:delete_static_dir(config(static_dir, Config)).
|
||||||
|
|
||||||
init_per_group(Name, Config) ->
|
init_per_group(Name, Config) ->
|
||||||
{_, Cert, Key} = ct_helper:make_certs(),
|
cowboy_test:init_spdy(Name, [
|
||||||
Opts = [{cert, Cert}, {key, Key}],
|
|
||||||
{ok, _} = cowboy:start_spdy(Name, 100, Opts ++ [{port, 0}], [
|
|
||||||
{env, [{dispatch, init_dispatch(Config)}]}
|
{env, [{dispatch, init_dispatch(Config)}]}
|
||||||
]),
|
], Config).
|
||||||
Port = ranch:get_port(Name),
|
|
||||||
[{port, Port}, {type, ssl}|Config].
|
|
||||||
|
|
||||||
end_per_group(Name, _) ->
|
end_per_group(Name, _) ->
|
||||||
cowboy:stop_listener(Name),
|
cowboy:stop_listener(Name).
|
||||||
ok.
|
|
||||||
|
|
||||||
%% Dispatch configuration.
|
%% Dispatch configuration.
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ groups() ->
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
init_per_group(autobahn, Config) ->
|
init_per_group(Name = autobahn, Config) ->
|
||||||
%% Some systems have it named pip2.
|
%% Some systems have it named pip2.
|
||||||
Out = os:cmd("pip show autobahntestsuite ; pip2 show autobahntestsuite"),
|
Out = os:cmd("pip show autobahntestsuite ; pip2 show autobahntestsuite"),
|
||||||
case string:str(Out, "autobahntestsuite") of
|
case string:str(Out, "autobahntestsuite") of
|
||||||
|
@ -40,21 +40,18 @@ init_per_group(autobahn, Config) ->
|
||||||
"http://autobahn.ws/testsuite/installation.html"),
|
"http://autobahn.ws/testsuite/installation.html"),
|
||||||
{skip, "Autobahn Test Suite not installed."};
|
{skip, "Autobahn Test Suite not installed."};
|
||||||
_ ->
|
_ ->
|
||||||
{ok, _} = cowboy:start_http(autobahn, 100, [{port, 33080}], [
|
{ok, _} = cowboy:start_http(Name, 100, [{port, 33080}], [
|
||||||
{env, [{dispatch, init_dispatch()}]}]),
|
{env, [{dispatch, init_dispatch()}]}]),
|
||||||
Config
|
Config
|
||||||
end;
|
end;
|
||||||
init_per_group(ws, Config) ->
|
init_per_group(Name = ws, Config) ->
|
||||||
cowboy:start_http(ws, 100, [{port, 0}], [
|
cowboy_test:init_http(Name, [
|
||||||
{env, [{dispatch, init_dispatch()}]},
|
{env, [{dispatch, init_dispatch()}]},
|
||||||
{compress, true}
|
{compress, true}
|
||||||
]),
|
], Config).
|
||||||
Port = ranch:get_port(ws),
|
|
||||||
[{port, Port}|Config].
|
|
||||||
|
|
||||||
end_per_group(Listener, _Config) ->
|
end_per_group(Listener, _Config) ->
|
||||||
cowboy:stop_listener(Listener),
|
cowboy:stop_listener(Listener).
|
||||||
ok.
|
|
||||||
|
|
||||||
%% Dispatch configuration.
|
%% Dispatch configuration.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue