aboutsummaryrefslogtreecommitdiffstats
path: root/test/spdy_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'test/spdy_SUITE.erl')
-rw-r--r--test/spdy_SUITE.erl141
1 files changed, 31 insertions, 110 deletions
diff --git a/test/spdy_SUITE.erl b/test/spdy_SUITE.erl
index c73c4f7..2e9c7e4 100644
--- a/test/spdy_SUITE.erl
+++ b/test/spdy_SUITE.erl
@@ -1,4 +1,4 @@
-%% Copyright (c) 2013, Loïc Hoguin <[email protected]>
+%% Copyright (c) 2013-2014, Loïc Hoguin <[email protected]>
%%
%% Permission to use, copy, modify, and/or distribute this software for any
%% purpose with or without fee is hereby granted, provided that the above
@@ -13,21 +13,10 @@
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-module(spdy_SUITE).
+-compile(export_all).
--include_lib("common_test/include/ct.hrl").
-
-%% ct.
--export([all/0]).
--export([groups/0]).
--export([init_per_suite/1]).
--export([end_per_suite/1]).
--export([init_per_group/2]).
--export([end_per_group/2]).
-
-%% Tests.
--export([check_status/1]).
--export([echo_body/1]).
--export([echo_body_multi/1]).
+-import(cowboy_test, [config/2]).
+-import(cowboy_test, [gun_monitor_open/1]).
%% ct.
@@ -35,55 +24,28 @@ all() ->
[{group, spdy}].
groups() ->
- [{spdy, [], [
- check_status,
- echo_body,
- echo_body_multi
- ]}].
+ [{spdy, [], cowboy_test:all(?MODULE)}].
init_per_suite(Config) ->
case proplists:get_value(ssl_app, ssl:versions()) of
Version when Version < "5.2.1" ->
{skip, "No NPN support in SSL application."};
_ ->
- application:start(crypto),
- application:start(cowlib),
- application:start(ranch),
- application:start(cowboy),
- application:start(asn1),
- application:start(public_key),
- application:start(ssl),
- application:start(gun),
- Dir = ?config(priv_dir, Config) ++ "/static",
+ Dir = config(priv_dir, Config) ++ "/static",
ct_helper:create_static_dir(Dir),
[{static_dir, Dir}|Config]
end.
end_per_suite(Config) ->
- Dir = ?config(static_dir, Config),
- ct_helper:delete_static_dir(Dir),
- application:stop(gun),
- application:stop(ssl),
- application:stop(public_key),
- application:stop(asn1),
- application:stop(cowboy),
- application:stop(ranch),
- application:stop(cowlib),
- application:stop(crypto),
- ok.
+ ct_helper:delete_static_dir(config(static_dir, Config)).
init_per_group(Name, Config) ->
- {_, Cert, Key} = ct_helper:make_certs(),
- Opts = [{cert, Cert}, {key, Key}],
- {ok, _} = cowboy:start_spdy(Name, 100, Opts ++ [{port, 0}], [
+ cowboy_test:init_spdy(Name, [
{env, [{dispatch, init_dispatch(Config)}]}
- ]),
- Port = ranch:get_port(Name),
- [{port, Port}|Config].
+ ], Config).
end_per_group(Name, _) ->
- cowboy:stop_listener(Name),
- ok.
+ cowboy:stop_listener(Name).
%% Dispatch configuration.
@@ -91,7 +53,7 @@ init_dispatch(Config) ->
cowboy_router:compile([
{"localhost", [
{"/static/[...]", cowboy_static,
- {dir, ?config(static_dir, Config)}},
+ {dir, config(static_dir, Config)}},
{"/echo/body", http_echo_body, []},
{"/chunked", http_chunked, []},
{"/", http_handler, []}
@@ -100,24 +62,14 @@ init_dispatch(Config) ->
%% Convenience functions.
-quick_get(Pid, Host, Path) ->
- MRef = monitor(process, Pid),
- StreamRef = gun:get(Pid, Path, [{":host", Host}]),
- receive
- {'DOWN', MRef, _, _, Reason} ->
- error(Reason);
- {gun_response, Pid, StreamRef, IsFin,
- << Status:3/binary, _/bits >>, Headers} ->
- {IsFin, list_to_integer(binary_to_list(Status)), Headers}
- after 1000 ->
- error(timeout)
- end.
+do_get(ConnPid, MRef, Host, Path) ->
+ StreamRef = gun:get(ConnPid, Path, [{":host", Host}]),
+ {response, IsFin, Status, _} = gun:await(ConnPid, StreamRef, MRef),
+ {IsFin, Status}.
%% Tests.
check_status(Config) ->
- {_, Port} = lists:keyfind(port, 1, Config),
- {ok, Pid} = gun:open("localhost", Port),
Tests = [
{200, nofin, "localhost", "/"},
{200, nofin, "localhost", "/chunked"},
@@ -126,64 +78,33 @@ check_status(Config) ->
{400, fin, "localhost", "bad-path"},
{404, fin, "localhost", "/this/path/does/not/exist"}
],
+ {ConnPid, MRef} = gun_monitor_open(Config),
_ = [{Status, Fin, Host, Path} = begin
- {IsFin, Ret, _} = quick_get(Pid, Host, Path),
+ {IsFin, Ret} = do_get(ConnPid, MRef, Host, Path),
{Ret, IsFin, Host, Path}
end || {Status, Fin, Host, Path} <- Tests],
- gun:close(Pid).
+ gun:close(ConnPid).
echo_body(Config) ->
- {_, Port} = lists:keyfind(port, 1, Config),
- {ok, Pid} = gun:open("localhost", Port),
- MRef = monitor(process, Pid),
+ {ConnPid, MRef} = gun_monitor_open(Config),
Body = << 0:800000 >>,
- StreamRef = gun:post(Pid, "/echo/body", [
- {<<"content-length">>, integer_to_list(byte_size(Body))},
+ StreamRef = gun:post(ConnPid, "/echo/body", [
{<<"content-type">>, "application/octet-stream"}
], Body),
- receive
- {'DOWN', MRef, _, _, Reason} ->
- error(Reason);
- {gun_response, Pid, StreamRef, nofin, << "200", _/bits >>, _} ->
- ok
- after 1000 ->
- error(response_timeout)
- end,
- receive
- {'DOWN', MRef, _, _, Reason2} ->
- error({gun_data, Reason2});
- {gun_data, Pid, StreamRef, fin, Body} ->
- ok
- after 1000 ->
- error(data_timeout)
- end,
- gun:close(Pid).
+ {response, nofin, 200, _} = gun:await(ConnPid, StreamRef, MRef),
+ {ok, Body} = gun:await_body(ConnPid, StreamRef, MRef),
+ gun:close(ConnPid).
echo_body_multi(Config) ->
- {_, Port} = lists:keyfind(port, 1, Config),
- {ok, Pid} = gun:open("localhost", Port),
- MRef = monitor(process, Pid),
+ {ConnPid, MRef} = gun_monitor_open(Config),
BodyChunk = << 0:80000 >>,
- StreamRef = gun:post(Pid, "/echo/body", [
+ StreamRef = gun:post(ConnPid, "/echo/body", [
+ %% @todo I'm still unhappy with this. It shouldn't be required...
{<<"content-length">>, integer_to_list(byte_size(BodyChunk) * 10)},
{<<"content-type">>, "application/octet-stream"}
]),
- _ = [gun:data(Pid, StreamRef, nofin, BodyChunk) || _ <- lists:seq(1, 9)],
- gun:data(Pid, StreamRef, fin, BodyChunk),
- receive
- {'DOWN', MRef, _, _, Reason} ->
- error(Reason);
- {gun_response, Pid, StreamRef, nofin, << "200", _/bits >>, _} ->
- ok
- after 1000 ->
- error(response_timeout)
- end,
- receive
- {'DOWN', MRef, _, _, Reason2} ->
- error({gun_data, Reason2});
- {gun_data, Pid, StreamRef, fin, << 0:800000 >>} ->
- ok
- after 1000 ->
- error(data_timeout)
- end,
- gun:close(Pid).
+ _ = [gun:data(ConnPid, StreamRef, nofin, BodyChunk) || _ <- lists:seq(1, 9)],
+ gun:data(ConnPid, StreamRef, fin, BodyChunk),
+ {response, nofin, 200, _} = gun:await(ConnPid, StreamRef, MRef),
+ {ok, << 0:800000 >>} = gun:await_body(ConnPid, StreamRef, MRef),
+ gun:close(ConnPid).