Browse Source

Move timeout tests from old_http_SUITE to http_SUITE

Also fix the idle_timeout test which was producing
an extra crash log.
Loïc Hoguin 7 years ago
parent
commit
0254c80c33
2 changed files with 37 additions and 50 deletions
  1. 36 1
      test/http_SUITE.erl
  2. 1 49
      test/old_http_SUITE.erl

+ 36 - 1
test/http_SUITE.erl

@@ -18,6 +18,7 @@
 
 -import(ct_helper, [config/2]).
 -import(ct_helper, [doc/1]).
+-import(ct_helper, [name/0]).
 -import(cowboy_test, [gun_open/1]).
 
 all() -> [{group, clear}].
@@ -26,10 +27,44 @@ groups() -> [{clear, [parallel], ct_helper:all(?MODULE)}].
 
 init_routes(_) -> [
 	{"localhost", [
-		{"/", hello_h, []}
+		{"/", hello_h, []},
+		{"/echo/:key", echo_h, []}
 	]}
 ].
 
+idle_timeout_infinity(Config) ->
+	doc("Ensure the idle_timeout option accepts the infinity value."),
+	{ok, ListenerPid} = cowboy:start_clear(name(), [{port, 0}], #{
+		env => #{dispatch => cowboy_router:compile(init_routes(Config))},
+		request_timeout => infinity
+	}),
+	Port = ranch:get_port(name()),
+	Ref = erlang:monitor(process, ListenerPid),
+	ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
+	_ = gun:post(ConnPid, "/echo/read_body", [], <<"TEST">>),
+	receive
+		{'DOWN', Ref, process, ListenerPid, Reason} ->
+			error(Reason)
+	after 1000 ->
+		ok
+	end.
+
+request_timeout_infinity(Config) ->
+	doc("Ensure the request_timeout option accepts the infinity value."),
+	{ok, ListenerPid} = cowboy:start_clear(name(), [{port, 0}], #{
+		env => #{dispatch => cowboy_router:compile(init_routes(Config))},
+		idle_timeout => infinity
+	}),
+	Port = ranch:get_port(name()),
+	Ref = erlang:monitor(process, ListenerPid),
+	_ = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
+	receive
+		{'DOWN', Ref, process, ListenerPid, Reason} ->
+			error(Reason)
+	after 1000 ->
+		ok
+	end.
+
 switch_protocol_flush(Config) ->
 	doc("Confirm that switch_protocol does not flush unrelated messages."),
 	ProtoOpts = #{

+ 1 - 49
test/old_http_SUITE.erl

@@ -35,16 +35,13 @@ all() ->
 		{group, http_compress},
 		{group, https_compress},
 		{group, parse_host},
-		{group, request_timeout_infinity},
-		{group, idle_timeout_infinity},
 		{group, set_env},
 		{group, router_compile}
 	].
 
 groups() ->
 	Tests = ct_helper:all(?MODULE) -- [
-		parse_host, set_env_dispatch, path_allow_colon,
-		request_timeout_infinity, idle_timeout_infinity
+		parse_host, set_env_dispatch, path_allow_colon
 	],
 	[
 		{http, [], Tests}, %% @todo parallel
@@ -54,12 +51,6 @@ groups() ->
 		{parse_host, [], [
 			parse_host
 		]},
-		{request_timeout_infinity, [], [
-			request_timeout_infinity
-		]},
-		{idle_timeout_infinity, [], [
-			idle_timeout_infinity
-		]},
 		{set_env, [], [
 			set_env_dispatch
 		]},
@@ -93,22 +84,6 @@ init_per_group(parse_host, Config) ->
 	}),
 	Port = ranch:get_port(parse_host),
 	[{type, tcp}, {protocol, http}, {port, Port}, {opts, []}|Config];
-init_per_group(request_timeout_infinity, Config) ->
-	Ref = request_timeout_infinity,
-	{ok, Pid} = cowboy:start_clear(Ref, [{port, 0}], #{
-		env => #{dispatch => init_dispatch(Config)},
-		request_timeout => infinity
-	}),
-	Port = ranch:get_port(request_timeout_infinity),
-	[{pid, Pid}, {ref, Ref}, {type, tcp}, {protocol, http}, {port, Port}, {opts, []}|Config];
-init_per_group(idle_timeout_infinity, Config) ->
-	Ref = idle_timeout_infinity,
-	{ok, Pid} = cowboy:start_clear(Ref, [{port, 0}], #{
-		env => #{dispatch => init_dispatch(Config)},
-		idle_timeout => infinity
-	}),
-	Port = ranch:get_port(idle_timeout_infinity),
-	[{pid, Pid}, {ref, Ref}, {type, tcp}, {protocol, http}, {port, Port}, {opts, []}|Config];
 init_per_group(set_env, Config) ->
 	{ok, _} = cowboy:start_clear(set_env, [{port, 0}], #{
 		env => #{dispatch => []}
@@ -732,26 +707,3 @@ te_identity(Config) ->
 	{response, nofin, 200, _} = gun:await(ConnPid, Ref),
 	{ok, Body} = gun:await_body(ConnPid, Ref),
 	ok.
-
-request_timeout_infinity(Config) ->
-	Pid = config(pid, Config),
-	Ref = erlang:monitor(process, Pid),
-	_ = gun_open(Config),
-	receive
-		{'DOWN', Ref, process, Pid, Reason} ->
-			error(Reason)
-	after 1000 ->
-		ok
-	end.
-
-idle_timeout_infinity(Config) ->
-	Pid = config(pid, Config),
-	Ref = erlang:monitor(process, Pid),
-	ConnPid = gun_open(Config),
-	gun:post(ConnPid, "/echo/body", [], <<"TEST">>),
-	receive
-		{'DOWN', Ref, process, Pid, Reason} ->
-			error(Reason)
-	after 1000 ->
-		ok
-	end.