aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-01-22 02:34:18 +0100
committerLoïc Hoguin <[email protected]>2013-01-22 02:34:18 +0100
commit647e95aed157edd58c86acdd774048593eb9d039 (patch)
tree07b4877b2d59a9c694d091eaa00c03d0b1dc4c80 /test
parent297ae32af1ad9b84558c4338f6caf82665d448e0 (diff)
downloadcowboy-647e95aed157edd58c86acdd774048593eb9d039.tar.gz
cowboy-647e95aed157edd58c86acdd774048593eb9d039.tar.bz2
cowboy-647e95aed157edd58c86acdd774048593eb9d039.zip
Replace terminate/2 with terminate/3, adding a Reason
This should have been done a *long* time ago, back when I initially added Websocket support. This is the first part of two in improving loop handler support with regards to socket closure. Reason may include: {normal, shutdown} for the most normal shutdown, {normal, timeout} for a loop handler timeout shutdown, or {error, _} if an error occured.
Diffstat (limited to 'test')
-rw-r--r--test/chunked_handler.erl4
-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_timeout_cancel_handler.erl9
-rw-r--r--test/ws_timeout_hibernate_handler.erl9
15 files changed, 25 insertions, 60 deletions
diff --git a/test/chunked_handler.erl b/test/chunked_handler.erl
index 38305fd..4a43c1a 100644
--- a/test/chunked_handler.erl
+++ b/test/chunked_handler.erl
@@ -2,7 +2,7 @@
-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}.
@@ -13,5 +13,5 @@ handle(Req, State) ->
cowboy_req:chunk("works fine!", Req2),
{ok, Req2, State}.
-terminate(_Req, _State) ->
+terminate(_, _, _) ->
ok.
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_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}.