# HG changeset patch # User Maxim Dounin # Date 1238245987 -10800 # Node ID d5330d926faca8a0cd7c3b4f97641ed89af9c5a5 # Parent c893908c1a44e26838a107317b6f4e3fc5c27e14 Tests: add test for limit_req not clearing write timeout on delay. diff --git a/lib/Test/Nginx.pm b/lib/Test/Nginx.pm --- a/lib/Test/Nginx.pm +++ b/lib/Test/Nginx.pm @@ -228,26 +228,26 @@ sub log_in { ############################################################################### -sub http_get($) { - my ($url) = @_; - return http(<print($request); local $/; + select undef, undef, undef, $extra{sleep} if $extra{sleep}; $reply = $s->getline(); log_in($reply); alarm(0); diff --git a/limit-req.t b/limit-req.t --- a/limit-req.t +++ b/limit-req.t @@ -21,7 +21,7 @@ use Test::Nginx; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->plan(2); +my $t = Test::Nginx->new()->plan(3); $t->write_file_expand('nginx.conf', <<'EOF'); @@ -39,6 +39,7 @@ http { proxy_temp_path %%TESTDIR%%/proxy_temp; limit_req_zone $binary_remote_addr zone=one:10m rate=1r/m; + limit_req_zone $binary_remote_addr zone=long:10m rate=1r/m; server { listen 127.0.0.1:8080; @@ -46,12 +47,16 @@ http { location / { limit_req zone=one burst=1 nodelay; } + location /long { + limit_req zone=long burst=5; + } } } EOF $t->write_file('test1.html', 'XtestX'); +$t->write_file('long.html', "1234567890\n" x (1 << 16)); $t->run(); ############################################################################### @@ -60,4 +65,17 @@ like(http_get('/test1.html'), qr/^HTTP\/ http_get('/test1.html'); like(http_get('/test1.html'), qr/^HTTP\/1.. 503 /m, 'request rejected'); +TODO: { +local $TODO = "patch under review"; + +# Second request will be delayed by limit_req, make sure it isn't truncated. +# The bug only manifests itself if buffer will be filled, so sleep for a while +# before reading response. + +my $l1 = length(http_get('/long.html')); +my $l2 = length(http_get('/long.html', sleep => 1.1)); +is($l2, $l1, 'delayed big request not truncated'); + +} + ###############################################################################