Tests: add test for limit_req not clearing write timeout on delay.
diff --git a/lib/Test/Nginx.pm b/lib/Test/Nginx.pm
index ca64ac7..ed2da14 100644
--- a/lib/Test/Nginx.pm
+++ b/lib/Test/Nginx.pm
@@ -228,26 +228,26 @@
###############################################################################
-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 @@
log_out($request);
$s->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
index 084d609..ba4efc3 100644
--- a/limit-req.t
+++ b/limit-req.t
@@ -21,7 +21,7 @@
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 @@
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 @@
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 @@
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');
+
+}
+
###############################################################################