Mercurial > hg > nginx-tests
annotate limit_req.t @ 487:c5ff54b56710
Tests: SPDY tests for empty header value.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 28 Oct 2014 20:56:21 +0300 |
parents | 6a0d934950bc |
children | 071e8941e3bf |
rev | line source |
---|---|
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for nginx limit_req module. |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
223
f9325406df0b
Tests: skip tests not appropriate for win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
172
diff
changeset
|
24 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
f9325406df0b
Tests: skip tests not appropriate for win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
172
diff
changeset
|
25 |
121
8ac1faaddd2c
Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents:
113
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http limit_req/)->plan(5); |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 $t->write_file_expand('nginx.conf', <<'EOF'); |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
103
diff
changeset
|
30 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
103
diff
changeset
|
31 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
223
diff
changeset
|
32 daemon off; |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 events { |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 } |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 http { |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
103
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
172
d099e407fff5
Tests: tune sleep in limit_req.t to avoid spurious timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
40 limit_req_zone $binary_remote_addr zone=one:10m rate=2r/s; |
d099e407fff5
Tests: tune sleep in limit_req.t to avoid spurious timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
41 limit_req_zone $binary_remote_addr zone=long:10m rate=2r/s; |
103
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
42 limit_req_zone $binary_remote_addr zone=fast:10m rate=1000r/s; |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 server { |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 listen 127.0.0.1:8080; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 server_name localhost; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 location / { |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 limit_req zone=one burst=1 nodelay; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 } |
79
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
50 location /long { |
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
51 limit_req zone=long burst=5; |
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
52 } |
103
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
53 location /fast { |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
54 limit_req zone=fast burst=1; |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
55 } |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 } |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 } |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 EOF |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 $t->write_file('test1.html', 'XtestX'); |
79
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
62 $t->write_file('long.html', "1234567890\n" x (1 << 16)); |
103
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
63 $t->write_file('fast.html', 'XtestX'); |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 $t->run(); |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 ############################################################################### |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 like(http_get('/test1.html'), qr/^HTTP\/1.. 200 /m, 'request'); |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 http_get('/test1.html'); |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 like(http_get('/test1.html'), qr/^HTTP\/1.. 503 /m, 'request rejected'); |
103
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
71 http_get('/test1.html'); |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
72 http_get('/test1.html'); |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 |
79
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
74 # Second request will be delayed by limit_req, make sure it isn't truncated. |
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
75 # The bug only manifests itself if buffer will be filled, so sleep for a while |
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
76 # before reading response. |
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
77 |
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
78 my $l1 = length(http_get('/long.html')); |
172
d099e407fff5
Tests: tune sleep in limit_req.t to avoid spurious timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
79 my $l2 = length(http_get('/long.html', sleep => 0.6)); |
79
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
80 is($l2, $l1, 'delayed big request not truncated'); |
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
81 |
103
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
82 # make sure rejected requests are not counted, and access is again allowed |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
83 # after 1/rate seconds |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
84 |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
85 like(http_get('/test1.html'), qr/^HTTP\/1.. 200 /m, 'rejects not counted'); |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
86 |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
87 # make sure negative excess values are handled properly |
113
5d31f920eda9
Tests: whitespace cleanup, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
107
diff
changeset
|
88 |
103
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
89 http_get('/fast.html'); |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
90 select undef, undef, undef, 0.1; |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
91 like(http_get('/fast.html'), qr/^HTTP\/1.. 200 /m, 'negative excess'); |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
92 |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 ############################################################################### |