Mercurial > hg > nginx-tests
comparison limit_req2.t @ 1363:e91d80dd2527
Tests: limit_req basic tests with multiple limits.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 07 Aug 2018 17:31:32 +0300 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1362:6874b32dc3d2 | 1363:e91d80dd2527 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for nginx limit_req module, multiple limits. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 my $t = Test::Nginx->new()->has(qw/http limit_req/)->plan(14); | |
26 | |
27 $t->write_file_expand('nginx.conf', <<'EOF'); | |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
37 %%TEST_GLOBALS_HTTP%% | |
38 | |
39 limit_req_zone $arg_a zone=slow:1m rate=1r/m; | |
40 limit_req_zone $arg_b zone=fast:1m rate=1000r/s; | |
41 | |
42 server { | |
43 listen 127.0.0.1:8080; | |
44 server_name localhost; | |
45 | |
46 location / { | |
47 limit_req zone=fast; | |
48 limit_req zone=slow; | |
49 } | |
50 | |
51 location /t2.html { | |
52 limit_req zone=fast nodelay; | |
53 limit_req zone=slow nodelay; | |
54 | |
55 alias %%TESTDIR%%/t1.html; | |
56 } | |
57 } | |
58 } | |
59 | |
60 EOF | |
61 | |
62 $t->write_file('t1.html', 'XtestX'); | |
63 $t->run(); | |
64 | |
65 ############################################################################### | |
66 | |
67 like(http_get('/t1.html?b=1'), qr/^HTTP\/1.. 200 /m, 'fast'); | |
68 select undef, undef, undef, 0.1; | |
69 like(http_get('/t1.html?b=1'), qr/^HTTP\/1.. 200 /m, 'fast - passed'); | |
70 | |
71 like(http_get('/t1.html?a=1'), qr/^HTTP\/1.. 200 /m, 'slow'); | |
72 select undef, undef, undef, 0.1; | |
73 like(http_get('/t1.html?a=1'), qr/^HTTP\/1.. 503 /m, 'slow - rejected'); | |
74 | |
75 like(http_get('/t1.html?a=2&b=2'), qr/^HTTP\/1.. 200 /m, 'both'); | |
76 select undef, undef, undef, 0.1; | |
77 like(http_get('/t1.html?a=2&b=2'), qr/^HTTP\/1.. 503 /m, 'both - rejected'); | |
78 | |
79 like(http_get('/t1.html'), qr/^HTTP\/1.. 200 /m, 'no key'); | |
80 like(http_get('/t1.html'), qr/^HTTP\/1.. 200 /m, 'no key - passed'); | |
81 | |
82 # nodelay | |
83 | |
84 like(http_get('/t2.html?b=3'), qr/^HTTP\/1.. 200 /m, 'nodelay fast'); | |
85 select undef, undef, undef, 0.1; | |
86 like(http_get('/t2.html?b=3'), qr/^HTTP\/1.. 200 /m, 'nodelay fast - passed'); | |
87 | |
88 like(http_get('/t2.html?a=3'), qr/^HTTP\/1.. 200 /m, 'nodelay slow'); | |
89 select undef, undef, undef, 0.1; | |
90 like(http_get('/t2.html?a=3'), qr/^HTTP\/1.. 503 /m, 'nodelay slow - rejected'); | |
91 | |
92 like(http_get('/t2.html?a=4&b=4'), qr/^HTTP\/1.. 200 /m, 'nodelay both'); | |
93 select undef, undef, undef, 0.1; | |
94 like(http_get('/t2.html?a=4&b=4'), qr/^HTTP\/1.. 503 /m, | |
95 'nodelay both - rejected'); | |
96 | |
97 ############################################################################### |