[PATCH] Tests: testing limit_req with "burst=A nodelay=B" configuration

Peter Shchuchkin peters at yandex.ru
Sun Oct 28 15:04:24 UTC 2018


# HG changeset patch
# User Peter Shchuchkin <peters at yandex.ru>
# Date 1540715681 -10800
#      Sun Oct 28 11:34:41 2018 +0300
# Node ID 9c629d98af7d8191f8ec5664b3d6ad33cb870d5c
# Parent  73a9504ae6fd61f75a3983784248b9cc0bd6e6c7
Tests: testing limit_req with "burst=A nodelay=B" configuration

diff -r 73a9504ae6fd -r 9c629d98af7d limit_req.t
--- a/limit_req.t	Fri Oct 19 18:49:45 2018 +0300
+++ b/limit_req.t	Sun Oct 28 11:34:41 2018 +0300
@@ -21,7 +21,7 @@
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-my $t = Test::Nginx->new()->has(qw/http limit_req/)->plan(6);
+my $t = Test::Nginx->new()->has(qw/http limit_req/)->plan(8);
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
@@ -38,6 +38,7 @@
     limit_req_zone  $binary_remote_addr  zone=one:1m   rate=2r/s;
     limit_req_zone  $binary_remote_addr  zone=long:1m  rate=2r/s;
     limit_req_zone  $binary_remote_addr  zone=fast:1m  rate=1000r/s;
+    limit_req_zone  $binary_remote_addr  zone=mixed:1m  rate=10r/s;
 
     server {
         listen       127.0.0.1:8080;
@@ -56,6 +57,12 @@
         location /fast {
             limit_req    zone=fast  burst=1;
         }
+        location /mixed {
+            limit_req    zone=mixed  burst=2 nodelay=1;
+        }
+        location /mixed-pass {
+            limit_req    zone=mixed  burst=2 nodelay;
+        }
     }
 }
 
@@ -64,6 +71,8 @@
 $t->write_file('test1.html', 'XtestX');
 $t->write_file('long.html', "1234567890\n" x (1 << 16));
 $t->write_file('fast.html', 'XtestX');
+$t->write_file('mixed.html', 'XtestX');
+$t->write_file('mixed-pass.html', 'XtestX');
 $t->run();
 
 ###############################################################################
@@ -94,4 +103,20 @@
 select undef, undef, undef, 0.1;
 like(http_get('/fast.html'), qr/^HTTP\/1.. 200 /m, 'negative excess');
 
+# make sure requests are delayed when 0 < nodelay < burst
+# this test should fail when using nodelay without =number
+
+http_get('/mixed.html');
+http_get('/mixed.html');
+http_get('/mixed.html');
+like(http_get('/mixed.html'), qr/^HTTP\/1.. 200 /m, 'mixed request is not rejected');
+
+# make sure it is possible to partially fill up excess through /mixed.html and get last request rejected
+# this test should fail when using "burst=N" without nodelay
+
+http_get('/mixed.html');
+http_get('/mixed.html');
+http_get('/mixed-pass.html');
+like(http_get('/mixed-pass.html'), qr/^HTTP\/1.. 503 /m, 'mixed request is rejected');
+
 ###############################################################################


More information about the nginx-devel mailing list