From 4bebe39975aab28962ac3850aa25a7d768c349bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sun, 22 Oct 2017 14:53:04 +0100 Subject: Ensure stream terminate is called when switching protocols --- test/handlers/stream_handler_h.erl | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/handlers/stream_handler_h.erl') diff --git a/test/handlers/stream_handler_h.erl b/test/handlers/stream_handler_h.erl index 23d6b15..36965ea 100644 --- a/test/handlers/stream_handler_h.erl +++ b/test/handlers/stream_handler_h.erl @@ -9,6 +9,9 @@ -export([terminate/3]). -export([early_error/5]). +%% For switch_protocol. +-export([takeover/7]). + -record(state, { pid, test @@ -43,6 +46,8 @@ init_commands(_, _, State=#state{test=shutdown_timeout_on_stream_stop}) -> init_commands(_, _, State=#state{test=shutdown_timeout_on_socket_close}) -> Spawn = init_process(true, State), [{headers, 200, #{}}, {spawn, Spawn, 2000}]; +init_commands(_, _, State=#state{test=terminate_on_switch_protocol}) -> + [{switch_protocol, #{}, ?MODULE, State}]; init_commands(_, _, State=#state{test=terminate_on_stop}) -> [{response, 204, #{}, <<>>}]; init_commands(_, _, _) -> @@ -94,3 +99,8 @@ early_error(StreamID, Reason, PartialReq, Resp, Opts) -> <<"crash_in_early_error",_/bits>> -> error(crash); _ -> Resp end. + +%% @todo It would be good if we could allow this function to return normally. +takeover(Parent, Ref, Socket, Transport, Opts, Buffer, State=#state{pid=Pid}) -> + Pid ! {Pid, self(), takeover, Parent, Ref, Socket, Transport, Opts, Buffer, State}, + exit(normal). -- cgit v1.2.3