aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/handlers/stream_handler_h.erl7
-rw-r--r--test/stream_handler_SUITE.erl20
2 files changed, 26 insertions, 1 deletions
diff --git a/test/handlers/stream_handler_h.erl b/test/handlers/stream_handler_h.erl
index 74fc478..23d6b15 100644
--- a/test/handlers/stream_handler_h.erl
+++ b/test/handlers/stream_handler_h.erl
@@ -43,6 +43,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_stop}) ->
+ [{response, 204, #{}, <<>>}];
init_commands(_, _, _) ->
[{headers, 200, #{}}].
@@ -72,7 +74,10 @@ info(_, crash, #state{test=crash_in_info}) ->
error(crash);
info(StreamID, Info, State=#state{pid=Pid}) ->
Pid ! {Pid, self(), info, StreamID, Info, State},
- {[], State}.
+ case Info of
+ please_stop -> {[stop], State};
+ _ -> {[], State}
+ end.
terminate(StreamID, Reason, State=#state{pid=Pid, test=crash_in_terminate}) ->
Pid ! {Pid, self(), terminate, StreamID, Reason, State},
diff --git a/test/stream_handler_SUITE.erl b/test/stream_handler_SUITE.erl
index 632adff..594e025 100644
--- a/test/stream_handler_SUITE.erl
+++ b/test/stream_handler_SUITE.erl
@@ -341,3 +341,23 @@ terminate_on_socket_close(Config) ->
%% Confirm terminate/3 is called.
receive {Self, Pid, terminate, _, _, _} -> ok after 1000 -> error(timeout) end,
ok.
+
+terminate_on_stop(Config) ->
+ doc("Confirm terminate/3 is called after stop is returned."),
+ Self = self(),
+ ConnPid = gun_open(Config),
+ Ref = gun:get(ConnPid, "/long_polling", [
+ {<<"accept-encoding">>, <<"gzip">>},
+ {<<"x-test-case">>, <<"terminate_on_stop">>},
+ {<<"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,
+ {response, fin, 204, _} = gun:await(ConnPid, Ref),
+ %% Confirm the stream is still alive even though we
+ %% received the response fully, and tell it to stop.
+ Pid ! {{Pid, 1}, please_stop},
+ receive {Self, Pid, info, _, please_stop, _} -> ok after 1000 -> error(timeout) end,
+ %% Confirm terminate/3 is called.
+ receive {Self, Pid, terminate, _, _, _} -> ok after 1000 -> error(timeout) end,
+ ok.