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

Remove the set_env test from old_http_SUITE

It duplicated a test in misc_SUITE. Also fix a couple issues
in misc_SUITE including a test that was not being executed.
This commit is contained in:
Loïc Hoguin 2018-05-17 21:04:40 +02:00
parent 36b32194b7
commit 753ba2e36d
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
2 changed files with 27 additions and 42 deletions

View file

@ -18,25 +18,31 @@
-import(ct_helper, [config/2]). -import(ct_helper, [config/2]).
-import(ct_helper, [doc/1]). -import(ct_helper, [doc/1]).
-import(ct_helper, [name/0]).
-import(cowboy_test, [gun_open/1]). -import(cowboy_test, [gun_open/1]).
all() -> all() ->
[{group, no_env}|cowboy_test:common_all()]. [{group, app}, {group, set_env}|cowboy_test:common_all()].
groups() -> groups() ->
Common = ct_helper:all(?MODULE) -- [restart_gracefully, set_env_missing], Common = ct_helper:all(?MODULE)
-- [restart_gracefully, set_env, set_env_missing],
[ [
{app, [], [restart_gracefully]}, {app, [], [restart_gracefully]},
{no_env, [], [set_env_missing]} {set_env, [parallel], [set_env, set_env_missing]}
|cowboy_test:common_groups(Common)]. |cowboy_test:common_groups(Common)].
init_per_group(app, Config) -> init_per_group(Name=app, Config) ->
cowboy_test:init_common_groups(http, Config, ?MODULE); cowboy_test:init_http(Name, #{
init_per_group(Name=no_env, Config) -> env => #{dispatch => init_dispatch(Config)}
cowboy_test:init_http(Name, #{}, Config); }, Config);
init_per_group(set_env, Config) ->
Config;
init_per_group(Name, Config) -> init_per_group(Name, Config) ->
cowboy_test:init_common_groups(Name, Config, ?MODULE). cowboy_test:init_common_groups(Name, Config, ?MODULE).
end_per_group(set_env, _) ->
ok;
end_per_group(Name, _) -> end_per_group(Name, _) ->
cowboy:stop_listener(Name). cowboy:stop_listener(Name).
@ -72,26 +78,28 @@ router_invalid_path(Config) ->
{response, _, 400, _} = gun:await(ConnPid, Ref), {response, _, 400, _} = gun:await(ConnPid, Ref),
ok. ok.
set_env(Config) -> set_env(Config0) ->
doc("Live replace a middleware environment value."), doc("Live replace a middleware environment value."),
Config = cowboy_test:init_http(name(), #{
env => #{dispatch => []}
}, Config0),
ConnPid1 = gun_open(Config), ConnPid1 = gun_open(Config),
Ref1 = gun:get(ConnPid1, "/"), Ref1 = gun:get(ConnPid1, "/"),
{response, _, 200, _} = gun:await(ConnPid1, Ref1), {response, _, 400, _} = gun:await(ConnPid1, Ref1),
Listener = proplists:get_value(name, config(tc_group_properties, Config)), cowboy:set_env(name(), dispatch, init_dispatch(Config)),
cowboy:set_env(Listener, dispatch, []),
%% Only new connections get the updated environment. %% Only new connections get the updated environment.
ConnPid2 = gun_open(Config), ConnPid2 = gun_open(Config),
Ref2 = gun:get(ConnPid2, "/"), Ref2 = gun:get(ConnPid2, "/"),
{response, _, 400, _} = gun:await(ConnPid2, Ref2), {response, _, 200, _} = gun:await(ConnPid2, Ref2),
ok. ok.
set_env_missing(Config) -> set_env_missing(Config0) ->
doc("Live replace a middleware environment value when env was not provided."), doc("Live replace a middleware environment value when env was not provided."),
Config = cowboy_test:init_http(name(), #{}, Config0),
ConnPid1 = gun_open(Config), ConnPid1 = gun_open(Config),
Ref1 = gun:get(ConnPid1, "/"), Ref1 = gun:get(ConnPid1, "/"),
{response, _, 500, _} = gun:await(ConnPid1, Ref1), {response, _, 500, _} = gun:await(ConnPid1, Ref1),
Listener = proplists:get_value(name, config(tc_group_properties, Config)), cowboy:set_env(name(), dispatch, []),
cowboy:set_env(Listener, dispatch, []),
%% Only new connections get the updated environment. %% Only new connections get the updated environment.
ConnPid2 = gun_open(Config), ConnPid2 = gun_open(Config),
Ref2 = gun:get(ConnPid2, "/"), Ref2 = gun:get(ConnPid2, "/"),

View file

@ -33,22 +33,16 @@ all() ->
{group, http}, {group, http},
{group, https}, {group, https},
{group, http_compress}, {group, http_compress},
{group, https_compress}, {group, https_compress}
{group, set_env}
]. ].
groups() -> groups() ->
Tests = ct_helper:all(?MODULE) -- [ Tests = ct_helper:all(?MODULE),
set_env_dispatch
],
[ [
{http, [], Tests}, %% @todo parallel {http, [], Tests}, %% @todo parallel
{https, [parallel], Tests}, {https, [parallel], Tests},
{http_compress, [parallel], Tests}, {http_compress, [parallel], Tests},
{https_compress, [parallel], Tests}, {https_compress, [parallel], Tests}
{set_env, [], [
set_env_dispatch
]}
]. ].
init_per_group(Name = http, Config) -> init_per_group(Name = http, Config) ->
@ -64,13 +58,7 @@ init_per_group(Name = https_compress, Config) ->
cowboy_test:init_https(Name, #{ cowboy_test:init_https(Name, #{
env => #{dispatch => init_dispatch(Config)}, env => #{dispatch => init_dispatch(Config)},
compress => true compress => true
}, Config); }, Config).
init_per_group(set_env, Config) ->
{ok, _} = cowboy:start_clear(set_env, [{port, 0}], #{
env => #{dispatch => []}
}),
Port = ranch:get_port(set_env),
[{type, tcp}, {protocol, http}, {port, Port}, {opts, []}|Config].
end_per_group(Name, _) -> end_per_group(Name, _) ->
ok = cowboy:stop_listener(Name). ok = cowboy:stop_listener(Name).
@ -519,17 +507,6 @@ rest_resource_etags_if_none_match(Config) ->
{Ret, Type} {Ret, Type}
end || {Status, ETag, Type} <- Tests]. end || {Status, ETag, Type} <- Tests].
set_env_dispatch(Config) ->
ConnPid1 = gun_open(Config),
Ref1 = gun:get(ConnPid1, "/"),
{response, fin, 400, _} = gun:await(ConnPid1, Ref1),
ok = cowboy:set_env(set_env, dispatch,
cowboy_router:compile([{'_', [{"/", http_handler, []}]}])),
ConnPid2 = gun_open(Config),
Ref2 = gun:get(ConnPid2, "/"),
{response, nofin, 200, _} = gun:await(ConnPid2, Ref2),
ok.
set_resp_overwrite(Config) -> set_resp_overwrite(Config) ->
ConnPid = gun_open(Config), ConnPid = gun_open(Config),
Ref = gun:get(ConnPid, "/set_resp/overwrite"), Ref = gun:get(ConnPid, "/set_resp/overwrite"),