aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/handlers/stream_handler_h.erl10
-rw-r--r--test/stream_handler_SUITE.erl23
2 files changed, 33 insertions, 0 deletions
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).
diff --git a/test/stream_handler_SUITE.erl b/test/stream_handler_SUITE.erl
index 594e025..33470eb 100644
--- a/test/stream_handler_SUITE.erl
+++ b/test/stream_handler_SUITE.erl
@@ -361,3 +361,26 @@ terminate_on_stop(Config) ->
%% Confirm terminate/3 is called.
receive {Self, Pid, terminate, _, _, _} -> ok after 1000 -> error(timeout) end,
ok.
+
+terminate_on_switch_protocol(Config) ->
+ case config(protocol, Config) of
+ http -> do_terminate_on_switch_protocol(Config);
+ http2 -> doc("The switch_protocol command is not currently supported for HTTP/2.")
+ end.
+
+do_terminate_on_switch_protocol(Config) ->
+ doc("Confirm terminate/3 is called after switch_protocol is returned."),
+ Self = self(),
+ ConnPid = gun_open(Config),
+ Ref = gun:get(ConnPid, "/long_polling", [
+ {<<"accept-encoding">>, <<"gzip">>},
+ {<<"x-test-case">>, <<"terminate_on_switch_protocol">>},
+ {<<"x-test-pid">>, pid_to_list(Self)}
+ ]),
+ %% Confirm init/3 is called and receive the response.
+ Pid = receive {Self, P, init, _, _, _} -> P after 1000 -> error(timeout) end,
+ %% Confirm terminate/3 is called.
+ receive {Self, Pid, terminate, _, _, _} -> ok after 1000 -> error(timeout) end,
+ %% Confirm takeover/7 is called.
+ receive {Self, Pid, takeover, _, _, _, _, _, _, _} -> ok after 1000 -> error(timeout) end,
+ ok.