aboutsummaryrefslogtreecommitdiffstats
path: root/test/sse_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'test/sse_SUITE.erl')
-rw-r--r--test/sse_SUITE.erl44
1 files changed, 36 insertions, 8 deletions
diff --git a/test/sse_SUITE.erl b/test/sse_SUITE.erl
index ce4dae3..f590f5b 100644
--- a/test/sse_SUITE.erl
+++ b/test/sse_SUITE.erl
@@ -19,7 +19,7 @@
-import(ct_helper, [config/2]).
all() ->
- [http, http2].
+ [http_clock, http2_clock, lone_id].
init_per_suite(Config) ->
gun_test:init_cowboy_tls(?MODULE, #{
@@ -31,30 +31,31 @@ end_per_suite(Config) ->
init_routes() -> [
{"localhost", [
- {"/", sse_clock_h, []}
+ {"/clock", sse_clock_h, []},
+ {"/lone_id", sse_lone_id_h, []}
]}
].
-http(Config) ->
+http_clock(Config) ->
{ok, Pid} = gun:open("localhost", config(port, Config), #{
transport => tls,
protocols => [http],
http_opts => #{content_handlers => [gun_sse_h, gun_data_h]}
}),
{ok, http} = gun:await_up(Pid),
- common(Pid).
+ do_clock_common(Pid).
-http2(Config) ->
+http2_clock(Config) ->
{ok, Pid} = gun:open("localhost", config(port, Config), #{
transport => tls,
protocols => [http2],
http2_opts => #{content_handlers => [gun_sse_h, gun_data_h]}
}),
{ok, http2} = gun:await_up(Pid),
- common(Pid).
+ do_clock_common(Pid).
-common(Pid) ->
- Ref = gun:get(Pid, "/", [
+do_clock_common(Pid) ->
+ Ref = gun:get(Pid, "/clock", [
{<<"host">>, <<"localhost">>},
{<<"accept">>, <<"text/event-stream">>}
]),
@@ -82,3 +83,30 @@ event_loop(Pid, Ref, N) ->
after 10000 ->
error(timeout)
end.
+
+lone_id(Config) ->
+ {ok, Pid} = gun:open("localhost", config(port, Config), #{
+ transport => tls,
+ protocols => [http],
+ http_opts => #{content_handlers => [gun_sse_h, gun_data_h]}
+ }),
+ {ok, http} = gun:await_up(Pid),
+ Ref = gun:get(Pid, "/lone_id", [
+ {<<"host">>, <<"localhost">>},
+ {<<"accept">>, <<"text/event-stream">>}
+ ]),
+ receive
+ {gun_response, Pid, Ref, nofin, 200, Headers} ->
+ {_, <<"text/event-stream">>}
+ = lists:keyfind(<<"content-type">>, 1, Headers),
+ receive
+ {gun_sse, Pid, Ref, Event} ->
+ #{last_event_id := <<"hello">>} = Event,
+ 1 = maps:size(Event),
+ gun:close(Pid)
+ after 10000 ->
+ error(timeout)
+ end
+ after 5000 ->
+ error(timeout)
+ end.