aboutsummaryrefslogtreecommitdiffstats
path: root/test/http_SUITE.erl
diff options
context:
space:
mode:
authorJames Fish <[email protected]>2013-11-18 20:32:47 +0000
committerJames Fish <[email protected]>2013-11-18 23:19:37 +0000
commit1c474af8ee4c61c9cbbf6ef4e121d1d82af75151 (patch)
treef13c6bf6ccefe64d8f913a8c566a560edbf7a21d /test/http_SUITE.erl
parent5a25c7f7f2167b8cef03129553e56f422a9890f2 (diff)
downloadcowboy-1c474af8ee4c61c9cbbf6ef4e121d1d82af75151.tar.gz
cowboy-1c474af8ee4c61c9cbbf6ef4e121d1d82af75151.tar.bz2
cowboy-1c474af8ee4c61c9cbbf6ef4e121d1d82af75151.zip
Fix loop handler keepalive race condition
Previously if a loop handler received the timeout message from a previous request on the same connection the socket would be set to {active, once} incorrectly - when a socket packet was already in the message queue. This second packet would not be added to the buffer before a Handler:info/3 call if a user message was in the message queue before both socket packets.
Diffstat (limited to 'test/http_SUITE.erl')
-rw-r--r--test/http_SUITE.erl24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl
index f0196ec..977cc1a 100644
--- a/test/http_SUITE.erl
+++ b/test/http_SUITE.erl
@@ -47,6 +47,7 @@
-export([http10_hostless/1]).
-export([keepalive_max/1]).
-export([keepalive_nl/1]).
+-export([keepalive_stream_loop/1]).
-export([multipart/1]).
-export([nc_rand/1]).
-export([nc_zero/1]).
@@ -132,6 +133,7 @@ groups() ->
http10_hostless,
keepalive_max,
keepalive_nl,
+ keepalive_stream_loop,
multipart,
nc_rand,
nc_zero,
@@ -407,6 +409,7 @@ init_dispatch(Config) ->
{"/rest_expires", rest_expires, []},
{"/rest_empty_resource", rest_empty_resource, []},
{"/loop_recv", http_loop_recv, []},
+ {"/loop_stream_recv", http_loop_stream_recv, []},
{"/loop_timeout", http_loop_timeout, []},
{"/", http_handler, []}
]}
@@ -725,6 +728,27 @@ keepalive_nl_loop(Client, URL, N) ->
ok = Transport:send(Socket, <<"\r\n">>), %% empty line
keepalive_nl_loop(Client3, URL, N - 1).
+keepalive_stream_loop(Config) ->
+ Client = ?config(client, Config),
+ Transport = ?config(transport, Config),
+ {ok, Client2} = cowboy_client:connect(
+ Transport, "localhost", ?config(port, Config), Client),
+ keepalive_stream_loop(Client2, 10).
+
+keepalive_stream_loop(Client, 0) ->
+ {error, closed} = cowboy_client:response(Client),
+ ok;
+keepalive_stream_loop(Client, N) ->
+ {ok, _} = cowboy_client:raw_request("POST /loop_stream_recv HTTP/1.1\r\n"
+ "Host: localhost\r\n"
+ "Connection: keepalive\r\n"
+ "Transfer-Encoding: chunked\r\n\r\n", Client),
+ _ = [{ok, _} = cowboy_client:raw_request(<<"4\r\n",Id:32,"\r\n">>, Client) ||
+ Id <- lists:seq(1, 250)],
+ {ok, _} = cowboy_client:raw_request(<<"0\r\n\r\n">>, Client),
+ {ok, 200, _, _} = cowboy_client:response(Client),
+ keepalive_stream_loop(Client, N-1).
+
multipart(Config) ->
Client = ?config(client, Config),
Body = <<