aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-08-09 15:03:55 +0200
committerLoïc Hoguin <[email protected]>2018-08-09 15:03:55 +0200
commitf3149399815257b934ca5c47c9b9f2d9de198bc6 (patch)
tree7221cbe2f5de613162559531fd5e5c7fbec7de4b
parenta66484cf97db7ce3fc56b9e8f23b93a4e3da03ec (diff)
downloadgun-f3149399815257b934ca5c47c9b9f2d9de198bc6.tar.gz
gun-f3149399815257b934ca5c47c9b9f2d9de198bc6.tar.bz2
gun-f3149399815257b934ca5c47c9b9f2d9de198bc6.zip
Add an SSE test for lone id: lines
-rw-r--r--test/handlers/sse_lone_id_h.erl19
-rw-r--r--test/sse_SUITE.erl44
2 files changed, 55 insertions, 8 deletions
diff --git a/test/handlers/sse_lone_id_h.erl b/test/handlers/sse_lone_id_h.erl
new file mode 100644
index 0000000..3684fa9
--- /dev/null
+++ b/test/handlers/sse_lone_id_h.erl
@@ -0,0 +1,19 @@
+%% This module implements a loop handler that sends
+%% a lone id: line.
+
+-module(sse_lone_id_h).
+
+-export([init/2]).
+-export([info/3]).
+
+init(Req, State) ->
+ self() ! timeout,
+ {cowboy_loop, cowboy_req:stream_reply(200, #{
+ <<"content-type">> => <<"text/event-stream">>
+ }, Req), State}.
+
+info(timeout, Req, State) ->
+ cowboy_req:stream_events(#{
+ id => <<"hello">>
+ }, nofin, Req),
+ {stop, Req, State}.
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.