aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/chunked_handler.erl6
-rw-r--r--test/http_SUITE.erl14
-rw-r--r--test/http_handler.erl4
-rw-r--r--test/http_handler_echo_body.erl4
-rw-r--r--test/http_handler_errors.erl4
-rw-r--r--test/http_handler_init_shutdown.erl4
-rw-r--r--test/http_handler_long_polling.erl4
-rw-r--r--test/http_handler_loop_timeout.erl4
-rw-r--r--test/http_handler_multipart.erl4
-rw-r--r--test/http_handler_set_resp.erl4
-rw-r--r--test/http_handler_stream_body.erl4
-rw-r--r--test/websocket_echo_handler.erl9
-rw-r--r--test/websocket_handler.erl9
-rw-r--r--test/websocket_handler_init_shutdown.erl9
-rw-r--r--test/ws_SUITE.erl2
-rw-r--r--test/ws_timeout_cancel_handler.erl9
-rw-r--r--test/ws_timeout_hibernate_handler.erl9
17 files changed, 36 insertions, 67 deletions
diff --git a/test/chunked_handler.erl b/test/chunked_handler.erl
index 38305fd..e486afe 100644
--- a/test/chunked_handler.erl
+++ b/test/chunked_handler.erl
@@ -2,16 +2,18 @@
-module(chunked_handler).
-behaviour(cowboy_http_handler).
--export([init/3, handle/2, terminate/2]).
+-export([init/3, handle/2, terminate/3]).
init({_Transport, http}, Req, _Opts) ->
{ok, Req, undefined}.
handle(Req, State) ->
{ok, Req2} = cowboy_req:chunked_reply(200, Req),
+ timer:sleep(100),
cowboy_req:chunk("chunked_handler\r\n", Req2),
+ timer:sleep(100),
cowboy_req:chunk("works fine!", Req2),
{ok, Req2, State}.
-terminate(_Req, _State) ->
+terminate(_, _, _) ->
ok.
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl
index 4791f36..61316db 100644
--- a/test/http_SUITE.erl
+++ b/test/http_SUITE.erl
@@ -155,7 +155,6 @@ groups() ->
].
init_per_suite(Config) ->
- application:start(inets),
application:start(crypto),
application:start(ranch),
application:start(cowboy),
@@ -165,7 +164,6 @@ end_per_suite(_Config) ->
application:stop(cowboy),
application:stop(ranch),
application:stop(crypto),
- application:stop(inets),
ok.
init_per_group(http, Config) ->
@@ -477,10 +475,16 @@ check_status(Config) ->
{Ret, URL}
end || {Status, URL} <- Tests].
-%% @todo Convert to cowboy_client.
chunked_response(Config) ->
- {ok, {{"HTTP/1.1", 200, "OK"}, _, "chunked_handler\r\nworks fine!"}}
- = httpc:request(binary_to_list(build_url("/chunked_response", Config))).
+ Client = ?config(client, Config),
+ {ok, Client2} = cowboy_client:request(<<"GET">>,
+ build_url("/chunked_response", Config), Client),
+ {ok, 200, Headers, Client3} = cowboy_client:response(Client2),
+ true = lists:keymember(<<"transfer-encoding">>, 1, Headers),
+ {ok, Transport, Socket} = cowboy_client:transport(Client3),
+ {ok, <<"11\r\nchunked_handler\r\n\r\nB\r\nworks fine!\r\n0\r\n\r\n">>}
+ = Transport:recv(Socket, 44, 1000),
+ {error, closed} = cowboy_client:response(Client3).
%% Check if sending requests whose size is around the MTU breaks something.
echo_body(Config) ->
diff --git a/test/http_handler.erl b/test/http_handler.erl
index e569adb..e1f1665 100644
--- a/test/http_handler.erl
+++ b/test/http_handler.erl
@@ -2,7 +2,7 @@
-module(http_handler).
-behaviour(cowboy_http_handler).
--export([init/3, handle/2, terminate/2]).
+-export([init/3, handle/2, terminate/3]).
-record(state, {headers, body}).
@@ -15,5 +15,5 @@ handle(Req, State=#state{headers=Headers, body=Body}) ->
{ok, Req2} = cowboy_req:reply(200, Headers, Body, Req),
{ok, Req2, State}.
-terminate(_Req, _State) ->
+terminate(_, _, _) ->
ok.
diff --git a/test/http_handler_echo_body.erl b/test/http_handler_echo_body.erl
index 37c2072..31595d5 100644
--- a/test/http_handler_echo_body.erl
+++ b/test/http_handler_echo_body.erl
@@ -2,7 +2,7 @@
-module(http_handler_echo_body).
-behaviour(cowboy_http_handler).
--export([init/3, handle/2, terminate/2]).
+-export([init/3, handle/2, terminate/3]).
init({_, http}, Req, _) ->
{ok, Req, undefined}.
@@ -15,5 +15,5 @@ handle(Req, State) ->
{ok, Req4} = cowboy_req:reply(200, [], Body, Req3),
{ok, Req4, State}.
-terminate(_, _) ->
+terminate(_, _, _) ->
ok.
diff --git a/test/http_handler_errors.erl b/test/http_handler_errors.erl
index 30cbaeb..2d1066c 100644
--- a/test/http_handler_errors.erl
+++ b/test/http_handler_errors.erl
@@ -2,7 +2,7 @@
-module(http_handler_errors).
-behaviour(cowboy_http_handler).
--export([init/3, handle/2, terminate/2]).
+-export([init/3, handle/2, terminate/3]).
init({_Transport, http}, Req, _Opts) ->
{Case, Req1} = cowboy_req:qs_val(<<"case">>, Req),
@@ -36,5 +36,5 @@ handle(Req, <<"handle_after_reply">> = Case) ->
{ok, _Req1} = cowboy_req:reply(200, [], "http_handler_crashes", Req),
erlang:error(Case).
-terminate(_Req, _State) ->
+terminate(_, _, _) ->
ok.
diff --git a/test/http_handler_init_shutdown.erl b/test/http_handler_init_shutdown.erl
index edea1a0..fd01983 100644
--- a/test/http_handler_init_shutdown.erl
+++ b/test/http_handler_init_shutdown.erl
@@ -2,7 +2,7 @@
-module(http_handler_init_shutdown).
-behaviour(cowboy_http_handler).
--export([init/3, handle/2, terminate/2]).
+-export([init/3, handle/2, terminate/3]).
init({_Transport, http}, Req, _Opts) ->
{ok, Req2} = cowboy_req:reply(<<"666 Init Shutdown Testing">>,
@@ -13,5 +13,5 @@ handle(Req, State) ->
{ok, Req2} = cowboy_req:reply(200, [], "Hello world!", Req),
{ok, Req2, State}.
-terminate(_Req, _State) ->
+terminate(_, _, _) ->
ok.
diff --git a/test/http_handler_long_polling.erl b/test/http_handler_long_polling.erl
index d61d697..763e1fe 100644
--- a/test/http_handler_long_polling.erl
+++ b/test/http_handler_long_polling.erl
@@ -2,7 +2,7 @@
-module(http_handler_long_polling).
-behaviour(cowboy_http_handler).
--export([init/3, handle/2, info/3, terminate/2]).
+-export([init/3, handle/2, info/3, terminate/3]).
init({_Transport, http}, Req, _Opts) ->
erlang:send_after(500, self(), timeout),
@@ -18,5 +18,5 @@ info(timeout, Req, State) ->
erlang:send_after(500, self(), timeout),
{loop, Req, State - 1, hibernate}.
-terminate(_Req, _State) ->
+terminate({normal, shutdown}, _, _) ->
ok.
diff --git a/test/http_handler_loop_timeout.erl b/test/http_handler_loop_timeout.erl
index c9bb15f..0155b1e 100644
--- a/test/http_handler_loop_timeout.erl
+++ b/test/http_handler_loop_timeout.erl
@@ -2,7 +2,7 @@
-module(http_handler_loop_timeout).
-behaviour(cowboy_loop_handler).
--export([init/3, info/3, terminate/2]).
+-export([init/3, info/3, terminate/3]).
init({_, http}, Req, _) ->
erlang:send_after(1000, self(), error_timeout),
@@ -12,5 +12,5 @@ info(error_timeout, Req, State) ->
{ok, Req2} = cowboy_req:reply(500, Req),
{ok, Req2, State}.
-terminate(_, _) ->
+terminate({normal, timeout}, _, _) ->
ok.
diff --git a/test/http_handler_multipart.erl b/test/http_handler_multipart.erl
index 850574f..8209535 100644
--- a/test/http_handler_multipart.erl
+++ b/test/http_handler_multipart.erl
@@ -2,7 +2,7 @@
-module(http_handler_multipart).
-behaviour(cowboy_http_handler).
--export([init/3, handle/2, terminate/2]).
+-export([init/3, handle/2, terminate/3]).
init({_Transport, http}, Req, []) ->
{ok, Req, {}}.
@@ -12,7 +12,7 @@ handle(Req, State) ->
{ok, Req3} = cowboy_req:reply(200, [], term_to_binary(Result), Req2),
{ok, Req3, State}.
-terminate(_Req, _State) ->
+terminate(_, _, _) ->
ok.
acc_multipart(Req) ->
diff --git a/test/http_handler_set_resp.erl b/test/http_handler_set_resp.erl
index 70ddf79..d00d72a 100644
--- a/test/http_handler_set_resp.erl
+++ b/test/http_handler_set_resp.erl
@@ -2,7 +2,7 @@
-module(http_handler_set_resp).
-behaviour(cowboy_http_handler).
--export([init/3, handle/2, terminate/2]).
+-export([init/3, handle/2, terminate/3]).
init({_Transport, http}, Req, Opts) ->
Headers = proplists:get_value(headers, Opts, []),
@@ -27,5 +27,5 @@ handle(Req, State) ->
end
end.
-terminate(_Req, _State) ->
+terminate(_, _, _) ->
ok.
diff --git a/test/http_handler_stream_body.erl b/test/http_handler_stream_body.erl
index d8f7d91..5e42fa7 100644
--- a/test/http_handler_stream_body.erl
+++ b/test/http_handler_stream_body.erl
@@ -2,7 +2,7 @@
-module(http_handler_stream_body).
-behaviour(cowboy_http_handler).
--export([init/3, handle/2, terminate/2]).
+-export([init/3, handle/2, terminate/3]).
-record(state, {headers, body, reply}).
@@ -24,5 +24,5 @@ handle(Req, State=#state{headers=_Headers, body=Body, reply=Reply}) ->
{ok, Req3} = cowboy_req:reply(200, Req2),
{ok, Req3, State}.
-terminate(_Req, _State) ->
+terminate(_, _, _) ->
ok.
diff --git a/test/websocket_echo_handler.erl b/test/websocket_echo_handler.erl
index 926b51d..21b0116 100644
--- a/test/websocket_echo_handler.erl
+++ b/test/websocket_echo_handler.erl
@@ -1,21 +1,14 @@
%% Feel free to use, reuse and abuse the code in this file.
-module(websocket_echo_handler).
--behaviour(cowboy_http_handler).
-behaviour(cowboy_websocket_handler).
--export([init/3, handle/2, terminate/2]).
+-export([init/3]).
-export([websocket_init/3, websocket_handle/3,
websocket_info/3, websocket_terminate/3]).
init(_Any, _Req, _Opts) ->
{upgrade, protocol, cowboy_websocket}.
-handle(_Req, _State) ->
- exit(badarg).
-
-terminate(_Req, _State) ->
- exit(badarg).
-
websocket_init(_TransportName, Req, _Opts) ->
Req2 = cowboy_req:compact(Req),
{ok, Req2, undefined}.
diff --git a/test/websocket_handler.erl b/test/websocket_handler.erl
index caf4828..a9863ae 100644
--- a/test/websocket_handler.erl
+++ b/test/websocket_handler.erl
@@ -1,21 +1,14 @@
%% Feel free to use, reuse and abuse the code in this file.
-module(websocket_handler).
--behaviour(cowboy_http_handler).
-behaviour(cowboy_websocket_handler).
--export([init/3, handle/2, terminate/2]).
+-export([init/3]).
-export([websocket_init/3, websocket_handle/3,
websocket_info/3, websocket_terminate/3]).
init(_Any, _Req, _Opts) ->
{upgrade, protocol, cowboy_websocket}.
-handle(_Req, _State) ->
- exit(badarg).
-
-terminate(_Req, _State) ->
- exit(badarg).
-
websocket_init(_TransportName, Req, _Opts) ->
erlang:start_timer(1000, self(), <<"websocket_init">>),
Req2 = cowboy_req:compact(Req),
diff --git a/test/websocket_handler_init_shutdown.erl b/test/websocket_handler_init_shutdown.erl
index 5fdfba3..7ccea05 100644
--- a/test/websocket_handler_init_shutdown.erl
+++ b/test/websocket_handler_init_shutdown.erl
@@ -1,21 +1,14 @@
%% Feel free to use, reuse and abuse the code in this file.
-module(websocket_handler_init_shutdown).
--behaviour(cowboy_http_handler).
-behaviour(cowboy_websocket_handler).
--export([init/3, handle/2, terminate/2]).
+-export([init/3]).
-export([websocket_init/3, websocket_handle/3,
websocket_info/3, websocket_terminate/3]).
init(_Any, _Req, _Opts) ->
{upgrade, protocol, cowboy_websocket}.
-handle(_Req, _State) ->
- exit(badarg).
-
-terminate(_Req, _State) ->
- exit(badarg).
-
websocket_init(_TransportName, Req, _Opts) ->
{ok, Req2} = cowboy_req:reply(403, Req),
{shutdown, Req2}.
diff --git a/test/ws_SUITE.erl b/test/ws_SUITE.erl
index 92fd98b..61bb236 100644
--- a/test/ws_SUITE.erl
+++ b/test/ws_SUITE.erl
@@ -63,7 +63,6 @@ groups() ->
[{ws, [], BaseTests}].
init_per_suite(Config) ->
- application:start(inets),
application:start(crypto),
application:start(ranch),
application:start(cowboy),
@@ -73,7 +72,6 @@ end_per_suite(_Config) ->
application:stop(cowboy),
application:stop(ranch),
application:stop(crypto),
- application:stop(inets),
ok.
init_per_group(ws, Config) ->
diff --git a/test/ws_timeout_cancel_handler.erl b/test/ws_timeout_cancel_handler.erl
index ee75d9b..68b0468 100644
--- a/test/ws_timeout_cancel_handler.erl
+++ b/test/ws_timeout_cancel_handler.erl
@@ -1,21 +1,14 @@
%% Feel free to use, reuse and abuse the code in this file.
-module(ws_timeout_cancel_handler).
--behaviour(cowboy_http_handler).
-behaviour(cowboy_websocket_handler).
--export([init/3, handle/2, terminate/2]).
+-export([init/3]).
-export([websocket_init/3, websocket_handle/3,
websocket_info/3, websocket_terminate/3]).
init(_Any, _Req, _Opts) ->
{upgrade, protocol, cowboy_websocket}.
-handle(_Req, _State) ->
- exit(badarg).
-
-terminate(_Req, _State) ->
- exit(badarg).
-
websocket_init(_TransportName, Req, _Opts) ->
erlang:start_timer(500, self(), should_not_cancel_timer),
{ok, Req, undefined, 1000}.
diff --git a/test/ws_timeout_hibernate_handler.erl b/test/ws_timeout_hibernate_handler.erl
index ac6ee4f..41b9edd 100644
--- a/test/ws_timeout_hibernate_handler.erl
+++ b/test/ws_timeout_hibernate_handler.erl
@@ -1,21 +1,14 @@
%% Feel free to use, reuse and abuse the code in this file.
-module(ws_timeout_hibernate_handler).
--behaviour(cowboy_http_handler).
-behaviour(cowboy_websocket_handler).
--export([init/3, handle/2, terminate/2]).
+-export([init/3]).
-export([websocket_init/3, websocket_handle/3,
websocket_info/3, websocket_terminate/3]).
init(_Any, _Req, _Opts) ->
{upgrade, protocol, cowboy_websocket}.
-handle(_Req, _State) ->
- exit(badarg).
-
-terminate(_Req, _State) ->
- exit(badarg).
-
websocket_init(_TransportName, Req, _Opts) ->
{ok, Req, undefined, 1000, hibernate}.