aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2015-04-12 16:35:22 +0300
committerLoïc Hoguin <[email protected]>2015-04-12 16:35:22 +0300
commit8d15999e1c4e74a4e76dbf79c7123ecb2190443f (patch)
tree25f7877d593f7fdc6ca038ea5aa6964ad01e5658 /test
parent1d49782d3f6d2c0a04918d43dee713bbb027504e (diff)
downloadgun-8d15999e1c4e74a4e76dbf79c7123ecb2190443f.tar.gz
gun-8d15999e1c4e74a4e76dbf79c7123ecb2190443f.tar.bz2
gun-8d15999e1c4e74a4e76dbf79c7123ecb2190443f.zip
Add more complex SPDY tests
These new tests have the spdy_server send frames back.
Diffstat (limited to 'test')
-rw-r--r--test/spdy_SUITE.erl32
-rw-r--r--test/spdy_server.erl35
2 files changed, 58 insertions, 9 deletions
diff --git a/test/spdy_SUITE.erl b/test/spdy_SUITE.erl
index 7dd6d34..28d9f7c 100644
--- a/test/spdy_SUITE.erl
+++ b/test/spdy_SUITE.erl
@@ -21,7 +21,7 @@ all() -> [{group, spdy31}].
groups() -> [{spdy31, [parallel], ct_helper:all(?MODULE)}].
-goaway_on_close(Config) ->
+goaway_on_close(_) ->
doc("Send a GOAWAY when the client closes the connection (spdy-protocol-draft3-1 2.1)"),
{ok, ServerPid, Port} = spdy_server:start_link(),
{ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
@@ -29,10 +29,38 @@ goaway_on_close(Config) ->
gun:close(ConnPid),
[{goaway, 0, ok}] = spdy_server:stop(ServerPid).
-goaway_on_shutdown(Config) ->
+goaway_on_shutdown(_) ->
doc("Send a GOAWAY when the client closes the connection (spdy-protocol-draft3-1 2.1)"),
{ok, ServerPid, Port} = spdy_server:start_link(),
{ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
{ok, spdy} = gun:await_up(ConnPid),
gun:shutdown(ConnPid),
[{goaway, 0, ok}] = spdy_server:stop(ServerPid).
+
+do_req_resp(ConnPid, ServerPid, ServerStreamID) ->
+ StreamRef = gun:get(ConnPid, "/"),
+ spdy_server:send(ServerPid, [
+ {syn_reply, ServerStreamID, false, <<"200">>, <<"HTTP/1.1">>, []},
+ {data, ServerStreamID, true, <<"Hello world!">>}
+ ]),
+ _ = gun:await(ConnPid, StreamRef),
+ ok.
+
+streamid_is_odd(_) ->
+ doc("Client-initiated Stream-ID must be an odd number. (spdy-protocol-draft3-1 2.3.2)"),
+ {ok, ServerPid, Port} = spdy_server:start_link(),
+ {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
+ {ok, spdy} = gun:await_up(ConnPid),
+ [do_req_resp(ConnPid, ServerPid, N * 2 - 1) || N <- lists:seq(1, 5)],
+ Rec = spdy_server:stop(ServerPid),
+ true = length(Rec) =:= length([ok || {syn_stream, StreamID, _, _, _, _, _, _, _, _, _, _} <- Rec, StreamID rem 2 =:= 1]).
+
+streamid_increases_monotonically(_) ->
+ doc("The Stream-ID must increase monotonically. (spdy-protocol-draft3-1 2.3.2)"),
+ {ok, ServerPid, Port} = spdy_server:start_link(),
+ {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
+ {ok, spdy} = gun:await_up(ConnPid),
+ Expected = [1, 3, 5, 7, 9],
+ [do_req_resp(ConnPid, ServerPid, N) || N <- Expected],
+ Rec = spdy_server:stop(ServerPid),
+ Expected = [StreamID || {syn_stream, StreamID, _, _, _, _, _, _, _, _, _, _} <- Rec].
diff --git a/test/spdy_server.erl b/test/spdy_server.erl
index e56c2da..0b3ec6d 100644
--- a/test/spdy_server.erl
+++ b/test/spdy_server.erl
@@ -18,6 +18,7 @@
%% API.
-export([start_link/0]).
-export([stop/1]).
+-export([send/2]).
%% gen_server.
-export([init/1]).
@@ -34,6 +35,7 @@
recording = [] :: recording(),
state_name = listen :: listen | record,
socket = undefined :: ssl:sslsocket(),
+ zdef = undefined :: zlib:zstream(),
zinf = undefined :: zlib:zstream(),
buffer = <<>> :: binary()
}).
@@ -53,6 +55,9 @@ start_link() ->
stop(Pid) ->
gen_server:call(Pid, stop).
+send(Pid, Frames) ->
+ gen_server:call(Pid, {send, Frames}).
+
%% gen_server.
init([Owner]) ->
@@ -62,8 +67,13 @@ init([Owner]) ->
{ok, {_, Port}} = ssl:sockname(LSocket),
Owner ! {port, self(), Port},
self() ! listen,
- {ok, #state{owner=Owner, socket=LSocket}}.
+ Zdef = cow_spdy:deflate_init(),
+ Zinf = cow_spdy:inflate_init(),
+ {ok, #state{owner=Owner, socket=LSocket, zdef=Zdef, zinf=Zinf}}.
+handle_call({send, Frames}, {Owner, _}, State=#state{owner=Owner, socket=Socket, zdef=Zdef}) ->
+ do_send(Frames, Socket, Zdef),
+ {reply, ok, State};
handle_call(stop, {Owner, _}, State=#state{owner=Owner, recording=Recording}) ->
{stop, normal, lists:reverse(Recording), State};
handle_call(_Request, _From, State) ->
@@ -85,6 +95,23 @@ handle_info({ssl, Socket, Data}, State=#state{state_name=record, socket=Socket,
handle_info(_Info, State) ->
{noreply, State}.
+terminate(_Reason, _State) ->
+ ok.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+%% Internal.
+
+do_send([], _, _) ->
+ ok;
+do_send([{syn_reply, StreamID, IsFin, Status, Version, Headers}|Tail], Socket, Zdef) ->
+ ssl:send(Socket, cow_spdy:syn_reply(Zdef, StreamID, IsFin, Status, Version, Headers)),
+ do_send(Tail, Socket, Zdef);
+do_send([{data, StreamID, IsFin, Data}|Tail], Socket, Zdef) ->
+ ssl:send(Socket, cow_spdy:data(StreamID, IsFin, Data)),
+ do_send(Tail, Socket, Zdef).
+
handle_data(Data, State=#state{recording=Recording, zinf=Zinf}) ->
case cow_spdy:split(Data) of
{true, ParsedFrame, Rest} ->
@@ -93,9 +120,3 @@ handle_data(Data, State=#state{recording=Recording, zinf=Zinf}) ->
false ->
State#state{buffer=Data}
end.
-
-terminate(_Reason, _State) ->
- ok.
-
-code_change(_OldVsn, State, _Extra) ->
- {ok, State}.