aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/event_SUITE.erl65
-rw-r--r--test/handlers/push_h.erl12
2 files changed, 76 insertions, 1 deletions
diff --git a/test/event_SUITE.erl b/test/event_SUITE.erl
index f7cae4e..ace509a 100644
--- a/test/event_SUITE.erl
+++ b/test/event_SUITE.erl
@@ -30,10 +30,12 @@ all() ->
groups() ->
Tests = ct_helper:all(?MODULE),
+ %% Push is not possible over HTTP/1.1.
+ PushTests = [T || T <- Tests, lists:sublist(atom_to_list(T), 5) =:= "push_"],
%% We currently do not support Websocket over HTTP/2.
WsTests = [T || T <- Tests, lists:sublist(atom_to_list(T), 3) =:= "ws_"],
[
- {http, [parallel], Tests},
+ {http, [parallel], Tests -- PushTests},
{http2, [parallel], Tests -- [protocol_changed|WsTests]}
].
@@ -43,6 +45,7 @@ init_per_suite(Config) ->
{"/", hello_h, []},
{"/empty", empty_h, []},
{"/inform", inform_h, []},
+ {"/push", push_h, []},
{"/stream", stream_h, []},
{"/trailers", trailers_h, []},
{"/ws", ws_echo, []}
@@ -343,6 +346,58 @@ do_request_end_headers_content_length_0(Config, EventName) ->
} = do_receive_event(EventName),
gun:close(Pid).
+push_promise_start(Config) ->
+ doc("Confirm that the push_promise_start event callback is called."),
+ {ok, Pid, _} = do_gun_open(Config),
+ {ok, _} = gun:await_up(Pid),
+ StreamRef = gun:get(Pid, "/push"),
+ ReplyTo = self(),
+ #{
+ stream_ref := StreamRef,
+ reply_to := ReplyTo
+ } = do_receive_event(?FUNCTION_NAME),
+ #{
+ stream_ref := StreamRef,
+ reply_to := ReplyTo
+ } = do_receive_event(?FUNCTION_NAME),
+ gun:close(Pid).
+
+push_promise_end(Config) ->
+ doc("Confirm that the push_promise_end event callback is called."),
+ {ok, Pid, _} = do_gun_open(Config),
+ {ok, _} = gun:await_up(Pid),
+ StreamRef = gun:get(Pid, "/push"),
+ ReplyTo = self(),
+ #{
+ stream_ref := StreamRef,
+ reply_to := ReplyTo,
+ promised_stream_ref := _,
+ method := <<"GET">>,
+ uri := <<"http://",_/bits>>,
+ headers := [_|_]
+ } = do_receive_event(?FUNCTION_NAME),
+ #{
+ stream_ref := StreamRef,
+ reply_to := ReplyTo,
+ promised_stream_ref := _,
+ method := <<"GET">>,
+ uri := <<"http://",_/bits>>,
+ headers := [_|_]
+ } = do_receive_event(?FUNCTION_NAME),
+ gun:close(Pid).
+
+push_promise_followed_by_response(Config) ->
+ doc("Confirm that the push_promise_end event callbacks are followed by response_start."),
+ {ok, Pid, _} = do_gun_open(Config),
+ {ok, _} = gun:await_up(Pid),
+ _ = gun:get(Pid, "/push"),
+ #{promised_stream_ref := PromisedStreamRef} = do_receive_event(push_promise_end),
+ #{stream_ref := StreamRef1} = do_receive_event(response_start),
+ #{stream_ref := StreamRef2} = do_receive_event(response_start),
+ #{stream_ref := StreamRef3} = do_receive_event(response_start),
+ true = lists:member(PromisedStreamRef, [StreamRef1, StreamRef2, StreamRef3]),
+ gun:close(Pid).
+
response_start(Config) ->
doc("Confirm that the request_start event callback is called."),
{ok, Pid, _} = do_gun_open(Config),
@@ -674,6 +729,14 @@ request_end(EventData, Pid) ->
Pid ! {?FUNCTION_NAME, EventData},
Pid.
+push_promise_start(EventData, Pid) ->
+ Pid ! {?FUNCTION_NAME, EventData},
+ Pid.
+
+push_promise_end(EventData, Pid) ->
+ Pid ! {?FUNCTION_NAME, EventData},
+ Pid.
+
response_start(EventData, Pid) ->
Pid ! {?FUNCTION_NAME, EventData},
Pid.
diff --git a/test/handlers/push_h.erl b/test/handlers/push_h.erl
new file mode 100644
index 0000000..4184227
--- /dev/null
+++ b/test/handlers/push_h.erl
@@ -0,0 +1,12 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+-module(push_h).
+
+-export([init/2]).
+
+init(Req, State) ->
+ cowboy_req:push("/", #{<<"accept">> => <<"text/plain">>}, Req),
+ cowboy_req:push("/empty", #{<<"accept">> => <<"text/plain">>}, Req),
+ {ok, cowboy_req:reply(200, #{
+ <<"content-type">> => <<"text/plain">>
+ }, <<"Hello world!">>, Req), State}.