changeset 79:d5330d926fac

Tests: add test for limit_req not clearing write timeout on delay.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 28 Mar 2009 16:13:07 +0300
parents c893908c1a44
children 14cf2658592d
files lib/Test/Nginx.pm limit-req.t
diffstat 2 files changed, 28 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/lib/Test/Nginx.pm
+++ b/lib/Test/Nginx.pm
@@ -228,26 +228,26 @@ sub log_in {
 
 ###############################################################################
 
-sub http_get($) {
-	my ($url) = @_;
-	return http(<<EOF);
+sub http_get($;%) {
+	my ($url, %extra) = @_;
+	return http(<<EOF, %extra);
 GET $url HTTP/1.0
 Host: localhost
 
 EOF
 }
 
-sub http_head($) {
-	my ($url) = @_;
-	return http(<<EOF);
+sub http_head($;%) {
+	my ($url, %extra) = @_;
+	return http(<<EOF, %extra);
 HEAD $url HTTP/1.0
 Host: localhost
 
 EOF
 }
 
-sub http($) {
-	my ($request) = @_;
+sub http($;%) {
+	my ($request, %extra) = @_;
 	my $reply;
 	eval {
 		local $SIG{ALRM} = sub { die "alarm\n" };
@@ -259,6 +259,7 @@ sub http($) {
 		log_out($request);
 		$s->print($request);
 		local $/;
+		select undef, undef, undef, $extra{sleep} if $extra{sleep};
 		$reply = $s->getline();
 		log_in($reply);
 		alarm(0);
--- 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');
+
+}
+
 ###############################################################################