aboutsummaryrefslogtreecommitdiffstats
path: root/test/http_SUITE.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-04-10 02:43:30 +0200
committerLoïc Hoguin <[email protected]>2011-04-10 02:43:30 +0200
commit0ef66b78f708d6f6f169649cbea76fabfa34f875 (patch)
tree42de01d9fbfdb74f1a23265a02e31ef8b481de3b /test/http_SUITE.erl
parentf05953516be489e8b4159f29e2db6b7920a2b45f (diff)
downloadcowboy-0ef66b78f708d6f6f169649cbea76fabfa34f875.tar.gz
cowboy-0ef66b78f708d6f6f169649cbea76fabfa34f875.tar.bz2
cowboy-0ef66b78f708d6f6f169649cbea76fabfa34f875.zip
ct: Add a test for requests pipelining.
Diffstat (limited to 'test/http_SUITE.erl')
-rw-r--r--test/http_SUITE.erl34
1 files changed, 32 insertions, 2 deletions
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl
index 628c6c9..663878b 100644
--- a/test/http_SUITE.erl
+++ b/test/http_SUITE.erl
@@ -18,7 +18,7 @@
-export([all/0, groups/0, init_per_suite/1, end_per_suite/1,
init_per_group/2, end_per_group/2]). %% ct.
--export([raw/1]). %% http.
+-export([pipeline/1, raw/1]). %% http.
-export([http_200/1, http_404/1]). %% http and https.
%% ct.
@@ -28,7 +28,7 @@ all() ->
groups() ->
BaseTests = [http_200, http_404],
- [{http, [], [raw] ++ BaseTests},
+ [{http, [], [pipeline, raw] ++ BaseTests},
{https, [], BaseTests}].
init_per_suite(Config) ->
@@ -84,6 +84,36 @@ init_https_dispatch() ->
%% http.
+pipeline(Config) ->
+ {port, Port} = lists:keyfind(port, 1, Config),
+ {ok, Socket} = gen_tcp:connect("localhost", Port,
+ [binary, {active, false}, {packet, raw}]),
+ ok = gen_tcp:send(Socket,
+ "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n"
+ "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n"
+ "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n"
+ "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n"
+ "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"),
+ Data = pipeline_recv(Socket, <<>>),
+ Reqs = binary:split(Data, << "\r\n\r\nhttp_handler" >>, [global, trim]),
+ 5 = length(Reqs),
+ pipeline_check(Reqs).
+
+pipeline_check([]) ->
+ ok;
+pipeline_check([Req|Tail]) ->
+ << "HTTP/1.1 200", _Rest/bits >> = Req,
+ pipeline_check(Tail).
+
+pipeline_recv(Socket, SoFar) ->
+ case gen_tcp:recv(Socket, 0, 6000) of
+ {ok, Data} ->
+ pipeline_recv(Socket, << SoFar/binary, Data/binary >>);
+ {error, closed} ->
+ ok = gen_tcp:close(Socket),
+ SoFar
+ end.
+
raw_req(Packet, Config) ->
{port, Port} = lists:keyfind(port, 1, Config),
{ok, Socket} = gen_tcp:connect("localhost", Port,