From 0ef66b78f708d6f6f169649cbea76fabfa34f875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sun, 10 Apr 2011 02:43:30 +0200 Subject: ct: Add a test for requests pipelining. --- test/http_SUITE.erl | 34 ++++++++++++++++++++++++++++++++-- 1 file 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, -- cgit v1.2.3